mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Vocabulary builder: store word context, other tweaks and fixes (#9195)
Add a copy button and save word context (off by default), shown via the three-dot menu of word entries. Also some db refactoring and minor UI improvements: - a dedicated book title table in order to shrink db size by storing references to title names instead of repeated actual strings, - alignment of different forms of the "more" button and possible clipped words in translations. - fix plugin name so it can be disabled
This commit is contained in:
@@ -1230,6 +1230,29 @@ dbg:guard(ReaderHighlight, "lookup",
|
||||
"lookup must not be called with nil selected_text!")
|
||||
end)
|
||||
|
||||
function ReaderHighlight:getSelectedWordContext(nb_words)
|
||||
if not self.ui.rolling or not self.selected_text then return nil end
|
||||
local pos_start = self.selected_text.pos0
|
||||
local pos_end = self.selected_text.pos1
|
||||
|
||||
for i=0, nb_words do
|
||||
local ok, start = pcall(self.ui.document.getPrevVisibleWordStart, self.ui.document, pos_start)
|
||||
if ok then pos_start = start
|
||||
else break end
|
||||
end
|
||||
|
||||
for i=0, nb_words do
|
||||
local ok, ending = pcall(self.ui.document.getNextVisibleWordEnd, self.ui.document, pos_end)
|
||||
if ok then pos_end = ending
|
||||
else break end
|
||||
end
|
||||
|
||||
local ok_prev, prev = pcall(self.ui.document.getTextFromXPointers, self.ui.document, pos_start, self.selected_text.pos0)
|
||||
local ok_next, next = pcall(self.ui.document.getTextFromXPointers, self.ui.document, self.selected_text.pos1, pos_end)
|
||||
|
||||
return ok_prev and prev, ok_next and next
|
||||
end
|
||||
|
||||
function ReaderHighlight:viewSelectionHTML(debug_view, no_css_files_buttons)
|
||||
if self.ui.document.info.has_pages then
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user