mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
TextBoxWidget: allow showing bits of text in bold
Allow for embedding "tags" (invalid Unicode codepoints) in the text string to trigger some text formatting: for now only bolding some parts of text is possible. Use it with fulltext search "all results" to highlight the matched word (instead of the previously used brackets).
This commit is contained in:
@@ -12,6 +12,7 @@ local FFIUtil = require("ffi/util")
|
||||
local Geom = require("ui/geometry")
|
||||
local KOPTContext = require("ffi/koptcontext")
|
||||
local Persist = require("persist")
|
||||
local TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
local TileCacheItem = require("document/tilecacheitem")
|
||||
local Utf8Proc = require("ffi/utf8proc")
|
||||
local logger = require("logger")
|
||||
@@ -1510,15 +1511,18 @@ function KoptInterface:findAllText(doc, pattern, case_insensitive, nb_context_wo
|
||||
i_next, j_next = i, j
|
||||
end
|
||||
end
|
||||
text = "【" .. table.concat(text, " ") .. "】"
|
||||
-- Make this word bolder, using Poor Text Formatting provided by TextBoxWidget
|
||||
-- (we know this text ends up in a TextBoxWidget).
|
||||
text = TextBoxWidget.PTF_BOLD_START .. table.concat(text, " ") .. TextBoxWidget.PTF_BOLD_END
|
||||
local prev_text = get_prev_text(text_boxes, i_prev, j_prev, nb_context_words)
|
||||
if prev_text then
|
||||
text = prev_text .. text
|
||||
text = prev_text .. " " .. text
|
||||
end
|
||||
local next_text = get_next_text(text_boxes, i_next, j_next, nb_context_words)
|
||||
if next_text then
|
||||
text = text .. next_text
|
||||
text = text .. " " .. next_text
|
||||
end
|
||||
text = TextBoxWidget.PTF_HEADER .. text -- enable handling of our bold tags
|
||||
res_item.text = text
|
||||
table.insert(res, res_item)
|
||||
if #res == max_hits then
|
||||
|
||||
Reference in New Issue
Block a user