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:
weijiuqiao
2022-06-13 03:34:17 +08:00
committed by GitHub
parent def02846ec
commit cafbf36bb2
7 changed files with 339 additions and 121 deletions

View File

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