[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
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

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()
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,

View File

@@ -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,14 +2672,16 @@ 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
if not keep_highlight then
self:clear()
end
end
-- dpad/keys support

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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)