mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
TextViewer: add support for long-press on text
As done in DictQuickLookup (more event handlers are needed to cohabitate well with MovableContainer). By default, selected word or text is copied to clipboard. Also provide indexes to any long-press callback, as we'll need them for View HTML.
This commit is contained in:
@@ -2012,7 +2012,10 @@ function TextBoxWidget:onHoldReleaseText(callback, ges)
|
||||
|
||||
logger.dbg("onHoldReleaseText (duration:", time.format_time(hold_duration), ") :",
|
||||
sel_start_idx, ">", sel_end_idx, "=", selected_text)
|
||||
callback(selected_text, hold_duration)
|
||||
-- We give index in the charlist (unicode chars), and provide a function
|
||||
-- to convert these indices as in the utf8 text, to be used by caller
|
||||
-- only if needed, as it may be expensive.
|
||||
callback(selected_text, hold_duration, sel_start_idx, sel_end_idx, function(idx) return self:getSourceIndex(idx) end)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -2029,7 +2032,7 @@ function TextBoxWidget:onHoldReleaseText(callback, ges)
|
||||
|
||||
local selected_text = table.concat(self.charlist, "", sel_start_idx, sel_end_idx)
|
||||
logger.dbg("onHoldReleaseText (duration:", time.format_time(hold_duration), ") :", sel_start_idx, ">", sel_end_idx, "=", selected_text)
|
||||
callback(selected_text, hold_duration)
|
||||
callback(selected_text, hold_duration, sel_start_idx, sel_end_idx, function(idx) return self:getSourceIndex(idx) end)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -2085,4 +2088,14 @@ function TextBoxWidget:_findWordEdge(x, y, side)
|
||||
return edge_idx
|
||||
end
|
||||
|
||||
function TextBoxWidget:getSourceIndex(char_idx)
|
||||
if self._xtext then
|
||||
local utf8 = self._xtext:getText(1, char_idx)
|
||||
return #utf8
|
||||
else
|
||||
local utf8 = table.concat(self.charlist, "", 1, char_idx)
|
||||
return #utf8
|
||||
end
|
||||
end
|
||||
|
||||
return TextBoxWidget
|
||||
|
||||
Reference in New Issue
Block a user