From 148449df6a97a4228551a46b9e5a61b3e0a04eb2 Mon Sep 17 00:00:00 2001 From: poire-z Date: Sun, 19 Apr 2026 22:09:29 +0200 Subject: [PATCH] Highlighting/lookup: avoid getting stuck when nothing selected Fixes 2 cases where we could get stuck in an exepected state: - if onHold would get us nothing to act on, we would stay stuck in "hold" state (until a next hold) and taps for page turn would not work - if text selection would get us some text (ie. some punctuation) that would be stripped to an empty string, we would just not do the lookup, but the selection would stay: best to do that lookup and get a "no result" window, that when closed would do the normal cleanup. --- frontend/apps/reader/modules/readerdictionary.lua | 8 ++++---- frontend/apps/reader/modules/readerhighlight.lua | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index 519c7e8e4..20ac3b700 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -589,6 +589,10 @@ function ReaderDictionary:onLookupWord(word, is_sane, boxes, highlight, link, di -- escape quotes and other funny characters in word word = self:cleanSelection(word, is_sane) logger.dbg("dict stripped word:", word) + -- (If word ends up empty, we still do the lookup, which will give us + -- a window with no result. This will ensure the normal cleanup of the + -- highlight when closing this "no result" window, which is easier than + -- trying to do it here if we were skipping the lookup.) self.highlight = highlight local disable_fuzzy_search @@ -1168,10 +1172,6 @@ function ReaderDictionary:startSdcv(word, dict_names, fuzzy_search) end function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes, link, dict_close_callback) - if word == "" then - return - end - local book_title = self.ui.doc_props and self.ui.doc_props.display_title or _("Dictionary lookup") -- Event for plugin to catch lookup with book title diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 510e727f8..4ca36dc66 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -1812,6 +1812,13 @@ function ReaderHighlight:onHold(arg, ges) end return true end + -- It has happened it failed because the text range was detected on the + -- previous page and highlighted by crengine, but no word was returned + -- (because the boxes were not on the current page). + -- Be sure we clear any such selection + self.ui.document:clearSelection() + -- And that we don't get stuck in a hold state + self.hold_pos = nil return false end