[ReaderHighlight] preserve highlight when using highlight dialogue (#14437)

This commit is contained in:
David
2025-10-14 14:22:27 +01:00
committed by GitHub
parent 4557ee9524
commit 6d49c261fa
8 changed files with 30 additions and 14 deletions

View File

@@ -47,6 +47,10 @@ DOVERLAPPIXELS = 30,
-- set to 0 to disable showing rectangle and follow link immediately -- set to 0 to disable showing rectangle and follow link immediately
FOLLOW_LINK_TIMEOUT = 0.5, 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) -- customizable tap zones(rectangles)
-- x: x coordinate of top left corner in proportion to screen width -- x: x coordinate of top left corner in proportion to screen width
-- y: y coordinate of top left corner in proportion to screen height -- y: y coordinate of top left corner in proportion to screen height

View File

@@ -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() Device:doExternalDictLookup(word, G_reader_settings:readSetting("external_dict_lookup_method"), function()
if self.highlight then if self.highlight then
local clear_id = self.highlight:getClearId() 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) self.highlight:clear(clear_id)
end) end)
end end
@@ -1356,7 +1356,7 @@ function ReaderDictionary:showNoResultsDialog(word, dict_names, fuzzy_search, bo
id = "close", id = "close",
callback = function(dialog) callback = function(dialog)
UIManager:close(dialog) UIManager:close(dialog)
UIManager:scheduleIn(0.5, function() lookupCancelled() end) UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), function() lookupCancelled() end)
end, end,
}, },
primary_action, primary_action,

View File

@@ -97,10 +97,13 @@ function ReaderHighlight:init()
enabled = Device:hasClipboard(), enabled = Device:hasClipboard(),
callback = function() callback = function()
Device.input.setClipboardText(util.cleanupSelectedText(this.selected_text.text)) Device.input.setClipboardText(util.cleanupSelectedText(this.selected_text.text))
this:onClose() this:onClose(true)
UIManager:show(Notification:new{ UIManager:show(Notification:new{
text = _("Selection copied to clipboard."), text = _("Selection copied to clipboard."),
}) })
UIManager:scheduleIn(G_defaults:readSetting("DELAY_CLEAR_HIGHLIGHT_S"), function()
this:clear()
end)
end, end,
} }
end, end,
@@ -134,7 +137,7 @@ function ReaderHighlight:init()
text = _("Dictionary"), text = _("Dictionary"),
callback = function() callback = function()
this:lookupDict(index) this:lookupDict(index)
-- We don't call this:onClose(), same reason as above this:onClose(true) -- keep highlight for dictionary lookup
end, end,
} }
end, end,
@@ -2100,7 +2103,7 @@ function ReaderHighlight:onHoldRelease()
self:onClose() self:onClose()
elseif default_highlight_action == "dictionary" then elseif default_highlight_action == "dictionary" then
self:lookupDict() self:lookupDict()
self:onClose() self:onClose(true) -- keep selected text
elseif default_highlight_action == "search" then elseif default_highlight_action == "search" then
self:onHighlightSearch() self:onHighlightSearch()
-- No self:onClose() to not remove the selected text -- 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) word_boxes[i] = self.view:pageToScreenTransform(self.selected_text.pos0.page, box)
end end
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
end end
@@ -2669,13 +2672,15 @@ function ReaderHighlight:onSaveSettings()
self.ui.doc_settings:saveSetting("panel_zoom_enabled", self.panel_zoom_enabled) self.ui.doc_settings:saveSetting("panel_zoom_enabled", self.panel_zoom_enabled)
end end
function ReaderHighlight:onClose() function ReaderHighlight:onClose(keep_highlight)
if self.highlight_dialog then if self.highlight_dialog then
UIManager:close(self.highlight_dialog) UIManager:close(self.highlight_dialog)
self.highlight_dialog = nil self.highlight_dialog = nil
end end
-- clear highlighted text -- clear highlighted text
self:clear() if not keep_highlight then
self:clear()
end
end end
-- dpad/keys support -- dpad/keys support

View File

@@ -1548,7 +1548,7 @@ function ReaderLink:showAsFootnotePopup(link, neglect_current_location)
-- it and know where to start reading again -- it and know where to start reading again
local footnote_top_y = Screen:getHeight() - footnote_height local footnote_top_y = Screen:getHeight() - footnote_height
if link.link_y > footnote_top_y then 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 else
clear_highlight() clear_highlight()
end end

View File

@@ -1301,7 +1301,7 @@ function DictQuickLookup:onClose(no_clear)
-- delay unhighlight of selection, so we can see where we stopped when -- delay unhighlight of selection, so we can see where we stopped when
-- back from our journey into dictionary or wikipedia -- back from our journey into dictionary or wikipedia
local clear_id = self.highlight:getClearId() 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) self.highlight:clear(clear_id)
end) end)
end end

View File

@@ -532,7 +532,7 @@ function HtmlBoxWidget:scheduleClearHighlightAndRedraw()
self:redrawHighlight() self:redrawHighlight()
end end
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 end
function HtmlBoxWidget:unscheduleClearHighlightAndRedraw() function HtmlBoxWidget:unscheduleClearHighlightAndRedraw()

View File

@@ -2381,7 +2381,7 @@ function TextBoxWidget:scheduleClearHighlightAndRedraw()
self:redrawHighlight() self:redrawHighlight()
end end
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 end
function TextBoxWidget:unscheduleClearHighlightAndRedraw() function TextBoxWidget:unscheduleClearHighlightAndRedraw()

View File

@@ -35,9 +35,16 @@ function QRClipboard:addToHighlightDialog()
UIManager:show(QRMessage:new{ UIManager:show(QRMessage:new{
text = Device.input.getClipboardText(), text = Device.input.getClipboardText(),
width = Device.screen:getWidth(), 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,
} }
end) end)