Fix early unhighlight after Add to vocab builder (#12288)

Getting text from xpointers to get the current selected
word context would have crengine unhighlight that word.
Allow to get it selected again when done getting context.
This commit is contained in:
poire-z
2024-08-04 23:27:30 +02:00
committed by GitHub
parent c213bd779c
commit 949b996ad7
2 changed files with 11 additions and 2 deletions

View File

@@ -766,7 +766,7 @@ function CreDocument:getNextVisibleChar(xp)
return self._document:getNextVisibleChar(xp)
end
function CreDocument:getSelectedWordContext(word, nb_words, pos0, pos1)
function CreDocument:getSelectedWordContext(word, nb_words, pos0, pos1, restore_selection)
local pos_start = pos0
local pos_end = pos1
@@ -785,6 +785,15 @@ function CreDocument:getSelectedWordContext(word, nb_words, pos0, pos1)
local prev = self:getTextFromXPointers(pos_start, pos0)
local next = self:getTextFromXPointers(pos1, pos_end)
if restore_selection then
-- If pos0..pos1 was highlighted by crengine, getTextFromXPointers()
-- will have cleared this original selection, and crengine would then
-- not draw it any longer on next refresh.
-- If requested because it was highlighted, have crengine know again
-- about what should be selected and drawn.
self:getTextFromXPointers(pos0, pos1, true)
end
return prev, next
end