From 6653080400065ee095025f39a4199a4c340d0785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sun, 17 Oct 2021 13:59:35 +0200 Subject: [PATCH] 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. --- src/gui/interface/TextWrapper.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gui/interface/TextWrapper.cpp b/src/gui/interface/TextWrapper.cpp index d2c1d93ac..7afce4e92 100644 --- a/src/gui/interface/TextWrapper.cpp +++ b/src/gui/interface/TextWrapper.cpp @@ -231,8 +231,7 @@ namespace ui return it; }; - auto next = find_next_nonempty(curr); - while (next != end) + while (true) { if (curr->pos_y + FONT_H > y) { @@ -243,6 +242,14 @@ namespace ui // the previous iteration 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 x is to the right of the vertical bisector of the current region @@ -257,7 +264,6 @@ namespace ui } } curr = next; - next = find_next_nonempty(next); } } return IndexEnd();