2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00

readersearch: fix building findall result

This commit is contained in:
hius07 2024-08-31 10:50:29 +03:00 committed by Frans de Jonge
parent 963aa9ac7c
commit 6f7277d269

View File

@ -629,20 +629,24 @@ function ReaderSearch:onShowFindAllResults(not_cached)
if not_cached then
for _, item in ipairs(self.findall_results) do
local text = { TextBoxWidget.PTF_HEADER } -- use Poor Text Formatting provided by TextBoxWidget
if item.prev_text then
table.insert(text, item.prev_text) -- append context before the word
if not item.prev_text:find("%s$") then -- separate prev context
table.insert(text, " ")
end
end
table.insert(text, TextBoxWidget.PTF_BOLD_START) -- start of the word in bold
-- PDF/Kopt shows full words when only some part matches; let's do the same with CRE
table.insert(text, item.matched_word_prefix)
table.insert(text, item.matched_text)
table.insert(text, item.matched_word_suffix)
table.insert(text, TextBoxWidget.PTF_BOLD_END) -- end of the word in bold
if item.next_text then
if not item.next_text:find("^[%s%p]") then -- separate next context
table.insert(text, " ")
end
table.insert(text, item.next_text) -- append context after the word
end
item.text = table.concat(text)
local pageno = self.ui.rolling and self.ui.document:getPageFromXPointer(item.start) or item.start