naive implementation of search highlight issue #75

This commit is contained in:
Dobrica Pavlinusic
2012-08-26 14:28:03 +02:00
parent 2a24f5a13a
commit ed59adecea
2 changed files with 51 additions and 1 deletions

View File

@@ -2462,6 +2462,56 @@ function UniReader:addAllCommands()
unireader:goto(unireader.pageno)
end
)
self.commands:add(KEY_DOT, nil, ".",
"search and highlight text",
function(unireader)
local search = InputBox:input(G_height - 100, 100,
"Search:")
if search == nil or string.len( search ) < 1 then
unireader:goto(unireader.pageno)
return nil
end
local t = self:getText(self.pageno)
if not t or #t == 0 then
showInfoMsgWithDelay("No text available for search", 2000, 1);
return nil
end
Debug("self:getText", self.pageno,t)
for i = 1, #t, 1 do
for j = 1, #t[i], 1 do
local e = t[i][j]
if e.word ~= nil then
if string.match( e.word, search ) then
if not self.highlight[self.pageno] then
self.highlight[self.pageno] = {}
end
local hl_item = {
text = e.word,
[1] = {
x0 = e.x0,
y0 = e.y0,
x1 = e.x1,
y1 = e.y1,
}
}
table.insert(self.highlight[self.pageno], hl_item)
end
end
end
end
Debug("self.highlight", self.highlight);
unireader:goto(unireader.pageno)
end
)
self.commands:add(KEY_P, MOD_SHIFT, "P",
"make screenshot",
function(unireader)