From b16c93bbe50c72130ef84b5bd508404c10f8426a Mon Sep 17 00:00:00 2001 From: poire-z Date: Sat, 27 Jan 2018 15:11:46 +0100 Subject: [PATCH] HtmlBoxWidget: fix selection when starting from end (#3632) --- frontend/ui/widget/htmlboxwidget.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/ui/widget/htmlboxwidget.lua b/frontend/ui/widget/htmlboxwidget.lua index 7b707d0d9..6bc2be5b3 100644 --- a/frontend/ui/widget/htmlboxwidget.lua +++ b/frontend/ui/widget/htmlboxwidget.lua @@ -162,9 +162,14 @@ function HtmlBoxWidget:getSelectedText(lines, start_pos, end_pos) for _, line in pairs(lines) do for _, w in pairs(line) do if type(w) == 'table' then - if (not found_start) and - (start_pos.x >= w.x0 and start_pos.x < w.x1 and start_pos.y >= w.y0 and start_pos.y < w.y1) then - found_start = true + if not found_start then + if start_pos.x >= w.x0 and start_pos.x < w.x1 and start_pos.y >= w.y0 and start_pos.y < w.y1 then + found_start = true + elseif end_pos.x >= w.x0 and end_pos.x < w.x1 and end_pos.y >= w.y0 and end_pos.y < w.y1 then + -- We found end_pos before start_pos, switch them + found_start = true + start_pos, end_pos = end_pos, start_pos + end end if found_start then