From ea67b9be77131ada5ddc1afa781f11ef934f76b5 Mon Sep 17 00:00:00 2001 From: poire-z Date: Sat, 14 Dec 2019 15:33:43 +0100 Subject: [PATCH] TextBoxWidget: fix crash on hold after end of text (#5689) --- frontend/ui/widget/textboxwidget.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index 1acbdfd51..7281c2d59 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -1744,6 +1744,15 @@ function TextBoxWidget:onHoldReleaseText(callback, ges) if sel_start_idx > sel_end_idx then -- re-order if needed sel_start_idx, sel_end_idx = sel_end_idx, sel_start_idx end + -- We get cursor positions, which can be after last char, + -- and that we need to correct. But if both positions are + -- after last char, the full selection is out of text. + if sel_start_idx > #self._xtext then -- Both are after last char + return true + end + if sel_end_idx > #self._xtext then -- Only end is after last char + sel_end_idx = #self._xtext + end -- Delegate word boundaries search to xtext.cpp, which can -- use libunibreak's wordbreak features. -- (50 is the nb of chars backward and ahead of selection indices