From 272d8857a243edf6c1c1a9b58ff993adac30b44b Mon Sep 17 00:00:00 2001 From: poire-z Date: Fri, 15 Nov 2019 15:14:34 +0100 Subject: [PATCH] TextBoxWidget: fix two minor bugs --- frontend/ui/widget/textboxwidget.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index ed6fa70c1..b89573f07 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -823,7 +823,7 @@ function TextBoxWidget:getCharPosAtXY(x, y) if x > self.vertical_string_list[ln].width then -- no need to loop thru chars local pos = self.vertical_string_list[ln].end_offset if not pos then -- empty line - pos = self.vertical_string_list[ln].offset + return self.vertical_string_list[ln].offset end return pos + 1 -- after last char end @@ -884,6 +884,12 @@ function TextBoxWidget:moveCursorToCharPos(charpos) -- needs to deal with possible overflow ? y = y - scroll_lines * self.line_height_px end + -- We can also get x ouside current view, when a line takes the full width + -- (which happens when text is justified): move the cursor a bit to the left + -- (it will be drawn over the right of the last glyph, which should be ok.) + if x > self.width - self.cursor_line.dimen.w then + x = self.width - self.cursor_line.dimen.w + end if not self._bb then return -- no bb yet to render the cursor too end