diff --git a/defaults.lua b/defaults.lua index 306d4483a..d78c7a7ea 100644 --- a/defaults.lua +++ b/defaults.lua @@ -47,6 +47,10 @@ DOVERLAPPIXELS = 30, -- set to 0 to disable showing rectangle and follow link immediately FOLLOW_LINK_TIMEOUT = 0.5, +-- delay before clearing highlighted text after dictionary queries +-- default to 0.5 second +DELAY_CLEAR_HIGHLIGHT_S = 0.5, + -- customizable tap zones(rectangles) -- x: x coordinate of top left corner in proportion to screen width -- y: y coordinate of top left corner in proportion to screen height diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index 82fe498cb..c0a63bc6c 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -1186,7 +1186,7 @@ function ReaderDictionary:stardictLookup(word, dict_names, fuzzy_search, boxes, Device:doExternalDictLookup(word, G_reader_settings:readSetting("external_dict_lookup_method"), function() if self.highlight then local clear_id = self.highlight:getClearId() - UIManager:scheduleIn(0.5, function() + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), function() self.highlight:clear(clear_id) end) end @@ -1356,7 +1356,7 @@ function ReaderDictionary:showNoResultsDialog(word, dict_names, fuzzy_search, bo id = "close", callback = function(dialog) UIManager:close(dialog) - UIManager:scheduleIn(0.5, function() lookupCancelled() end) + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), function() lookupCancelled() end) end, }, primary_action, diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 3e38fdf0e..4bef2d482 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -97,10 +97,13 @@ function ReaderHighlight:init() enabled = Device:hasClipboard(), callback = function() Device.input.setClipboardText(util.cleanupSelectedText(this.selected_text.text)) - this:onClose() + this:onClose(true) UIManager:show(Notification:new{ text = _("Selection copied to clipboard."), }) + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), function() + this:clear() + end) end, } end, @@ -134,7 +137,7 @@ function ReaderHighlight:init() text = _("Dictionary"), callback = function() this:lookupDict(index) - -- We don't call this:onClose(), same reason as above + this:onClose(true) -- keep highlight for dictionary lookup end, } end, @@ -2100,7 +2103,7 @@ function ReaderHighlight:onHoldRelease() self:onClose() elseif default_highlight_action == "dictionary" then self:lookupDict() - self:onClose() + self:onClose(true) -- keep selected text elseif default_highlight_action == "search" then self:onHighlightSearch() -- No self:onClose() to not remove the selected text @@ -2296,7 +2299,7 @@ function ReaderHighlight:lookupDict(index) word_boxes[i] = self.view:pageToScreenTransform(self.selected_text.pos0.page, box) end end - self.ui.dictionary:onLookupWord(util.cleanupSelectedText(self.selected_text.text), false, word_boxes) + self.ui.dictionary:onLookupWord(util.cleanupSelectedText(self.selected_text.text), false, word_boxes, self) end end @@ -2669,13 +2672,15 @@ function ReaderHighlight:onSaveSettings() self.ui.doc_settings:saveSetting("panel_zoom_enabled", self.panel_zoom_enabled) end -function ReaderHighlight:onClose() +function ReaderHighlight:onClose(keep_highlight) if self.highlight_dialog then UIManager:close(self.highlight_dialog) self.highlight_dialog = nil end -- clear highlighted text - self:clear() + if not keep_highlight then + self:clear() + end end -- dpad/keys support diff --git a/frontend/apps/reader/modules/readerlink.lua b/frontend/apps/reader/modules/readerlink.lua index 1dd699306..158b73322 100644 --- a/frontend/apps/reader/modules/readerlink.lua +++ b/frontend/apps/reader/modules/readerlink.lua @@ -1548,7 +1548,7 @@ function ReaderLink:showAsFootnotePopup(link, neglect_current_location) -- it and know where to start reading again local footnote_top_y = Screen:getHeight() - footnote_height if link.link_y > footnote_top_y then - UIManager:scheduleIn(0.5, clear_highlight) + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), clear_highlight) else clear_highlight() end diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index 5d2729d97..eb8bf69b9 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -1301,7 +1301,7 @@ function DictQuickLookup:onClose(no_clear) -- delay unhighlight of selection, so we can see where we stopped when -- back from our journey into dictionary or wikipedia local clear_id = self.highlight:getClearId() - UIManager:scheduleIn(0.5, function() + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), function() self.highlight:clear(clear_id) end) end diff --git a/frontend/ui/widget/htmlboxwidget.lua b/frontend/ui/widget/htmlboxwidget.lua index 6b08a01b3..63d5b5f2e 100644 --- a/frontend/ui/widget/htmlboxwidget.lua +++ b/frontend/ui/widget/htmlboxwidget.lua @@ -532,7 +532,7 @@ function HtmlBoxWidget:scheduleClearHighlightAndRedraw() self:redrawHighlight() end end - UIManager:scheduleIn(0.5, self.highlight_clear_and_redraw_action) + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), self.highlight_clear_and_redraw_action) end function HtmlBoxWidget:unscheduleClearHighlightAndRedraw() diff --git a/frontend/ui/widget/textboxwidget.lua b/frontend/ui/widget/textboxwidget.lua index 9b025e9be..b88c8bddb 100644 --- a/frontend/ui/widget/textboxwidget.lua +++ b/frontend/ui/widget/textboxwidget.lua @@ -2381,7 +2381,7 @@ function TextBoxWidget:scheduleClearHighlightAndRedraw() self:redrawHighlight() end end - UIManager:scheduleIn(0.5, self.highlight_clear_and_redraw_action) + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), self.highlight_clear_and_redraw_action) end function TextBoxWidget:unscheduleClearHighlightAndRedraw() diff --git a/plugins/qrclipboard.koplugin/main.lua b/plugins/qrclipboard.koplugin/main.lua index c972f3790..f900a015c 100644 --- a/plugins/qrclipboard.koplugin/main.lua +++ b/plugins/qrclipboard.koplugin/main.lua @@ -35,9 +35,16 @@ function QRClipboard:addToHighlightDialog() UIManager:show(QRMessage:new{ text = Device.input.getClipboardText(), width = Device.screen:getWidth(), - height = Device.screen:getHeight() + height = Device.screen:getHeight(), + dismiss_callback = function() + -- delay clearing highlighted text a bit, so the user can see + -- what was used to generate the QR code + UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), function() + this:clear() + end) + end, }) - this:onClose() + this:onClose(true) end, } end)