Fix: Layouter::GetCharAtPosition counting wrong

Bug introduced in commit 60399e
pull/603/head
Niels Martin Hansen 12 months ago
parent 31cc349a09
commit ed3f14686d

@ -255,9 +255,9 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const
}
/**
* Get the character that is at a position.
* Get the character that is at a pixel position in the first line of the layouted text.
* @param x Position in the string.
* @return Index of the position or -1 if no character is at the position.
* @return String offset of the position (bytes) or -1 if no character is at the position.
*/
ptrdiff_t Layouter::GetCharAtPosition(int x) const
{
@ -278,9 +278,8 @@ ptrdiff_t Layouter::GetCharAtPosition(int x) const
size_t index = run.GetGlyphToCharMap()[i];
size_t cur_idx = 0;
int char_index = 0;
for (auto str = this->string.begin(); str != this->string.end(); char_index++) {
if (cur_idx == index) return char_index;
for (auto str = this->string.begin(); str != this->string.end();) {
if (cur_idx == index) return str - this->string.begin();
WChar c = Utf8Consume(str);
cur_idx += line->GetInternalCharLength(c);

Loading…
Cancel
Save