Fix cursor placement in textboxes with single-character text

TextWrapper used faulty logic for converting local points to wrapped text indices: a check on curr was skipped if next was end-of-range.
This commit is contained in:
Tamás Bálint Misius 2021-10-17 13:59:35 +02:00
parent afa9fd3d8f
commit 6653080400
No account linked to committer's email address

View File

@ -231,8 +231,7 @@ namespace ui
return it; return it;
}; };
auto next = find_next_nonempty(curr); while (true)
while (next != end)
{ {
if (curr->pos_y + FONT_H > y) if (curr->pos_y + FONT_H > y)
{ {
@ -243,6 +242,14 @@ namespace ui
// the previous iteration // the previous iteration
return curr->index; return curr->index;
} }
}
auto next = find_next_nonempty(curr);
if (next == end)
{
break;
}
if (curr->pos_y + FONT_H > y)
{
if (curr->pos_x + curr->width / 2 <= x && next->pos_x + next->width / 2 > x) if (curr->pos_x + curr->width / 2 <= x && next->pos_x + next->width / 2 > x)
{ {
// if x is to the right of the vertical bisector of the current region // if x is to the right of the vertical bisector of the current region
@ -257,7 +264,6 @@ namespace ui
} }
} }
curr = next; curr = next;
next = find_next_nonempty(next);
} }
} }
return IndexEnd(); return IndexEnd();