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.
This commit is contained in:
1 parent
61f4542b6b
commit
148449df6a
2 files changed
+11
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user