1
0
Fork 0

Fix: Layouter::GetCharAtPosition counting wrong

Bug introduced in commit 60399e
pull/11041/head
Niels Martin Hansen 2023-06-18 19:26:53 +02:00
parent 31cc349a09
commit ed3f14686d
1 changed files with 4 additions and 5 deletions

View File

@ -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. * @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 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 index = run.GetGlyphToCharMap()[i];
size_t cur_idx = 0; size_t cur_idx = 0;
int char_index = 0; for (auto str = this->string.begin(); str != this->string.end();) {
for (auto str = this->string.begin(); str != this->string.end(); char_index++) { if (cur_idx == index) return str - this->string.begin();
if (cur_idx == index) return char_index;
WChar c = Utf8Consume(str); WChar c = Utf8Consume(str);
cur_idx += line->GetInternalCharLength(c); cur_idx += line->GetInternalCharLength(c);