mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
VocabBuilder.koplugin: support PDF context extraction for multi-word phrase (#12917)
Closes #12916. Closes #12475.
This commit is contained in:
@@ -1196,9 +1196,22 @@ function KoptInterface:getSelectedWordContext(word, nb_words, pos)
|
|||||||
local boxes = self.last_text_boxes
|
local boxes = self.last_text_boxes
|
||||||
if not pos or not boxes or #boxes == 0 then return end
|
if not pos or not boxes or #boxes == 0 then return end
|
||||||
local i, j = getWordBoxIndices(boxes, pos)
|
local i, j = getWordBoxIndices(boxes, pos)
|
||||||
|
local i_end, j_end = i, j
|
||||||
|
local word_array = util.splitToArray(word, " ")
|
||||||
|
for idx, split_word in ipairs(word_array) do
|
||||||
|
if boxes[i_end][j_end].word ~= split_word then return end
|
||||||
|
if idx ~= #word_array then
|
||||||
|
if j_end == #boxes[i_end] then
|
||||||
|
i_end = i_end + 1
|
||||||
|
j_end = 1
|
||||||
|
else
|
||||||
|
j_end = j_end + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if boxes[i][j].word ~= word then return end
|
if boxes[i][j].word ~= word then return end
|
||||||
local prev_text = get_prev_text(boxes, i, j, nb_words)
|
local prev_text = get_prev_text(boxes, i, j, nb_words)
|
||||||
local next_text = get_next_text(boxes, i, j, nb_words)
|
local next_text = get_next_text(boxes, i_end, j_end, nb_words)
|
||||||
return prev_text, next_text
|
return prev_text, next_text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user