mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[fix] Optimize cre highlights onTap and drawing (#3508)
drawXPointerSavedHighlight() and onTapXPointerSavedHighlight were looping thru all credocuments highlights, which was expensive. Now, we first check with cheaper getPageFromXPointer() the highlights are on the current page before doing more expensive stuff. Closes #3503.
This commit is contained in:
@@ -178,7 +178,7 @@ function ReaderHighlight:onTapPageSavedHighlight(ges)
|
||||
if boxes then
|
||||
for index, box in pairs(boxes) do
|
||||
if inside_box(pos, box) then
|
||||
logger.dbg("Tap on hightlight")
|
||||
logger.dbg("Tap on highlight")
|
||||
return self:onShowHighlightDialog(page, i)
|
||||
end
|
||||
end
|
||||
@@ -189,18 +189,39 @@ function ReaderHighlight:onTapPageSavedHighlight(ges)
|
||||
end
|
||||
|
||||
function ReaderHighlight:onTapXPointerSavedHighlight(ges)
|
||||
local cur_page
|
||||
-- In scroll mode, we'll need to check for highlights in previous or next
|
||||
-- page too as some parts of them may be displayed
|
||||
local neighbour_pages = self.view.view_mode ~= "page" and 1 or 0
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
for page, _ in pairs(self.view.highlight.saved) do
|
||||
local items = self.view.highlight.saved[page]
|
||||
if items then
|
||||
for i = 1, #items do
|
||||
if not cur_page then
|
||||
cur_page = self.ui.document:getPageFromXPointer(self.ui.document:getXPointer())
|
||||
end
|
||||
local pos0, pos1 = items[i].pos0, items[i].pos1
|
||||
local boxes = self.ui.document:getScreenBoxesFromPositions(pos0, pos1)
|
||||
if boxes then
|
||||
for index, box in pairs(boxes) do
|
||||
if inside_box(pos, box) then
|
||||
logger.dbg("Tap on hightlight")
|
||||
return self:onShowHighlightDialog(page, i)
|
||||
-- document:getScreenBoxesFromPositions() is expensive, so we
|
||||
-- first check this item is on current page
|
||||
local page0 = self.ui.document:getPageFromXPointer(pos0)
|
||||
local page1 = self.ui.document:getPageFromXPointer(pos1)
|
||||
local start_page = math.min(page0, page1)
|
||||
local end_page = math.max(page0, page1)
|
||||
-- In scroll mode, we may be displaying cur_page and cur_page+1, so
|
||||
-- we have to check the highlight start_page is <= cur_page+1.
|
||||
-- Same thinking with highlight's end_page >= cur_page-1 as we may
|
||||
-- be displaying a part of cur_page-1.
|
||||
-- (A highlight starting on cur_page-17 and ending on cur_page+13 is
|
||||
-- a highlight to consider)
|
||||
if start_page <= cur_page + neighbour_pages and end_page >= cur_page - neighbour_pages then
|
||||
local boxes = self.ui.document:getScreenBoxesFromPositions(pos0, pos1)
|
||||
if boxes then
|
||||
for index, box in pairs(boxes) do
|
||||
if inside_box(pos, box) then
|
||||
logger.dbg("Tap on highlight")
|
||||
return self:onShowHighlightDialog(page, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -561,7 +582,7 @@ function ReaderHighlight:saveHighlight()
|
||||
self.ui.bookmark:addBookmark(bookmark_item)
|
||||
end
|
||||
--[[
|
||||
-- disable exporting hightlights to My Clippings
|
||||
-- disable exporting highlights to My Clippings
|
||||
-- since it's not portable and there is a better Evernote plugin
|
||||
-- to do the same thing
|
||||
if self.selected_text.text ~= "" then
|
||||
|
||||
Reference in New Issue
Block a user