From 09982fe6cb3f8576e3290ae0647ef99b9a3cf065 Mon Sep 17 00:00:00 2001 From: David <97603719+Commodore64user@users.noreply.github.com> Date: Mon, 16 Feb 2026 14:23:02 +0000 Subject: [PATCH] NT: stop text selection before any reflow action occurs (#14949) * refactor onStopHighlightIndicator so it returns early * stop text selection when opening menus or triggering hotkeys * use self.ui.highlight (naturally) * remove duplicated setDirty --- frontend/apps/reader/modules/readerconfig.lua | 1 + .../apps/reader/modules/readerhighlight.lua | 24 +++++++++---------- frontend/apps/reader/modules/readermenu.lua | 1 + plugins/hotkeys.koplugin/main.lua | 3 +++ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/frontend/apps/reader/modules/readerconfig.lua b/frontend/apps/reader/modules/readerconfig.lua index 6d09f25fa..563375b3f 100644 --- a/frontend/apps/reader/modules/readerconfig.lua +++ b/frontend/apps/reader/modules/readerconfig.lua @@ -135,6 +135,7 @@ function ReaderConfig:onShowConfigMenu() covers_footer = true, close_callback = function() self:onCloseCallback() end, } + self.ui.highlight:onStopHighlightIndicator(true) -- stop any text selection in progress, if applicable self.ui:handleEvent(Event:new("DisableHinting")) -- show last used panel when opening config dialog self.config_dialog:onShowConfigPanel(self.last_panel_index) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 5220b78ef..c25191f4b 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -2780,7 +2780,6 @@ function ReaderHighlight:onHighlightPress(skip_tap_check) pos.y + pos.h / 2 - self._current_indicator_pos.h / 2 ) end - UIManager:setDirty(self.dialog, "ui", self._current_indicator_pos) return true end @@ -2819,6 +2818,7 @@ function ReaderHighlight:onStartHighlightIndicator() end function ReaderHighlight:onStopHighlightIndicator(need_clear_selection) + if not self._current_indicator_pos then return false end -- If we're in select mode and user presses back, end the selection if self.select_mode and self.highlight_idx then self.select_mode = false @@ -2829,19 +2829,17 @@ function ReaderHighlight:onStopHighlightIndicator(need_clear_selection) end self.highlight_idx = nil end - if self._current_indicator_pos then - local rect = self._current_indicator_pos - self._previous_indicator_pos = rect - self._start_indicator_highlight = false - self._current_indicator_pos = nil - self.view.highlight.indicator = nil - UIManager:setDirty(self.dialog, "ui", rect) - if need_clear_selection then - self:clear() - end - return true + + local rect = self._current_indicator_pos + self._previous_indicator_pos = rect + self._start_indicator_highlight = false + self._current_indicator_pos = nil + self.view.highlight.indicator = nil + UIManager:setDirty(self.dialog, "ui", rect) + if need_clear_selection then + self:clear() end - return false + return true end function ReaderHighlight:onMoveHighlightIndicator(args) diff --git a/frontend/apps/reader/modules/readermenu.lua b/frontend/apps/reader/modules/readermenu.lua index 0145fb290..3018da12f 100644 --- a/frontend/apps/reader/modules/readermenu.lua +++ b/frontend/apps/reader/modules/readermenu.lua @@ -412,6 +412,7 @@ function ReaderMenu:exitOrRestart(callback, force) end function ReaderMenu:onShowMenu(tab_index, do_not_show) + self.ui.highlight:onStopHighlightIndicator(true) -- stop any text selection in progress, if applicable if self.tab_item_table == nil then self:setUpdateItemTable() end diff --git a/plugins/hotkeys.koplugin/main.lua b/plugins/hotkeys.koplugin/main.lua index 636f2eea3..0386496d8 100644 --- a/plugins/hotkeys.koplugin/main.lua +++ b/plugins/hotkeys.koplugin/main.lua @@ -87,6 +87,9 @@ end @return (boolean) Returns true if the hotkey action was successfully executed, otherwise returns nil. ]] function HotKeys:onHotkeyAction(hotkey) + -- Note: we could have started text selection and then trigger a reflow through hotkeys (e.g., increase + -- font-size) which will cause pandemonium to ensue (invalid coordinates). + if self.ui.highlight then self.ui.highlight:stopHighlightIndicator(true) end local hotkey_action_list = self.hotkeys[hotkey] local context = self.is_docless and "FileManager" or "Reader" if hotkey_action_list == nil then