mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Annotations: fixes 2 (#11788)
* readerbookmark: fix index for reverse sorting * readerhighlight: fix pdf tap on highlight detection
This commit is contained in:
@@ -524,25 +524,25 @@ function ReaderBookmark:onShowBookmark(match_table)
|
||||
self.show_edited_only = nil
|
||||
self.select_mode = false
|
||||
self.filtered_mode = match_table and true or false
|
||||
self.is_reverse_sorting = G_reader_settings:nilOrTrue("bookmarks_items_reverse_sorting") -- page numbers descending
|
||||
|
||||
-- build up item_table
|
||||
local item_table = {}
|
||||
local is_reverse_sorting = G_reader_settings:nilOrTrue("bookmarks_items_reverse_sorting") -- page numbers descending
|
||||
local curr_page_num = self:getCurrentPageNumber()
|
||||
local curr_page_string = self:getBookmarkPageString(curr_page_num)
|
||||
local curr_page_index = self.ui.annotation:getInsertionIndex({page = curr_page_num})
|
||||
local num = #self.ui.annotation.annotations + 1
|
||||
curr_page_index = is_reverse_sorting and num - curr_page_index or curr_page_index
|
||||
curr_page_index = self.is_reverse_sorting and num - curr_page_index or curr_page_index
|
||||
local curr_page_index_filtered = curr_page_index
|
||||
for i = 1, #self.ui.annotation.annotations do
|
||||
local v = self.ui.annotation.annotations[is_reverse_sorting and num - i or i]
|
||||
local v = self.ui.annotation.annotations[self.is_reverse_sorting and num - i or i]
|
||||
local item = util.tableDeepCopy(v)
|
||||
item.text_orig = item.text or ""
|
||||
item.type = self.getBookmarkType(item)
|
||||
if not match_table or self:doesBookmarkMatchTable(item, match_table) then
|
||||
item.text = self:getBookmarkItemText(item)
|
||||
item.mandatory = self:getBookmarkPageString(item.page)
|
||||
if (not is_reverse_sorting and i >= curr_page_index) or (is_reverse_sorting and i <= curr_page_index) then
|
||||
if (not self.is_reverse_sorting and i >= curr_page_index) or (self.is_reverse_sorting and i <= curr_page_index) then
|
||||
item.after_curr_page = true
|
||||
item.mandatory_dim = true
|
||||
end
|
||||
@@ -910,7 +910,7 @@ function ReaderBookmark:onShowBookmark(match_table)
|
||||
callback = function()
|
||||
UIManager:close(bm_dialog)
|
||||
local _, idx = bookmark:getLatestBookmark()
|
||||
idx = is_reverse_sorting and #item_table - idx + 1 or idx
|
||||
idx = self.is_reverse_sorting and #item_table - idx + 1 or idx
|
||||
bm_menu:switchItemTable(nil, item_table, idx)
|
||||
bm_menu:onMenuHold(item_table[idx])
|
||||
end,
|
||||
@@ -961,6 +961,11 @@ function ReaderBookmark:onShowBookmark(match_table)
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderBookmark:getBookmarkItemIndex(item)
|
||||
return (self.filtered_mode or self.show_edited_only) and self.ui.annotation:getItemIndex(item)
|
||||
or (self.is_reverse_sorting and #self.ui.annotation.annotations - item.idx + 1 or item.idx)
|
||||
end
|
||||
|
||||
function ReaderBookmark:getBookmarkItemText(item)
|
||||
if item.type == "highlight" or self.items_text == "text" then
|
||||
return self.display_prefix[item.type] .. item.text_orig
|
||||
@@ -995,7 +1000,7 @@ function ReaderBookmark:setBookmarkNote(item_or_index, is_new_note, new_note)
|
||||
index = item_or_index
|
||||
else
|
||||
item = item_or_index -- in item_table
|
||||
index = (self.filtered_mode or self.show_edited_only) and self.ui.annotation:getItemIndex(item) or item.idx
|
||||
index = self:getBookmarkItemIndex(item)
|
||||
end
|
||||
local annotation = self.ui.annotation.annotations[index]
|
||||
local type_before = item and item.type or self.getBookmarkType(annotation)
|
||||
@@ -1119,7 +1124,7 @@ function ReaderBookmark:setHighlightedText(item, text)
|
||||
end
|
||||
end
|
||||
-- annotation
|
||||
local index = (self.filtered_mode or self.show_edited_only) and self.ui.annotation:getItemIndex(item) or item.idx
|
||||
local index = self:getBookmarkItemIndex(item)
|
||||
self.ui.annotation.annotations[index].text = text
|
||||
self.ui.annotation.annotations[index].text_edited = edited
|
||||
-- item table
|
||||
|
||||
@@ -722,14 +722,14 @@ function ReaderHighlight:onTapPageSavedHighlight(ges)
|
||||
local pos = self.view:screenToPageTransform(ges.pos)
|
||||
local highlights_tapped = {}
|
||||
for _, page in ipairs(pages) do
|
||||
local items = self:getPageSavedHighlights(page)
|
||||
local items, idx_offset = self:getPageSavedHighlights(page)
|
||||
for i, item in ipairs(items) do
|
||||
local boxes = self.ui.document:getPageBoxesFromPositions(page, item.pos0, item.pos1)
|
||||
if boxes then
|
||||
for __, box in ipairs(boxes) do
|
||||
if inside_box(pos, box) then
|
||||
logger.dbg("Tap on highlight")
|
||||
local hl_i = item.parent or i -- parent exists in multi-page highlight only
|
||||
local hl_i = item.parent or (i + idx_offset) -- parent exists in multi-page highlight only
|
||||
if self.select_mode then
|
||||
if hl_i == self.highlight_idx then
|
||||
-- tap on the first fragment: abort select mode, clear highlight
|
||||
@@ -2018,9 +2018,13 @@ end
|
||||
-- The list includes full single-page highlights and parts of multi-page highlights.
|
||||
-- (For pdf documents only)
|
||||
function ReaderHighlight:getPageSavedHighlights(page)
|
||||
local idx_offset
|
||||
local highlights = {}
|
||||
for index, highlight in ipairs(self.ui.annotation.annotations) do
|
||||
if highlight.drawer and highlight.pos0.page <= page and page <= highlight.pos1.page then
|
||||
if idx_offset == nil then
|
||||
idx_offset = index - 1
|
||||
end
|
||||
if highlight.ext then -- multi-page highlight
|
||||
local item = self:getSavedExtendedHighlightPage(highlight, page, index)
|
||||
table.insert(highlights, item)
|
||||
@@ -2029,7 +2033,7 @@ function ReaderHighlight:getPageSavedHighlights(page)
|
||||
end
|
||||
end
|
||||
end
|
||||
return highlights
|
||||
return highlights, idx_offset
|
||||
end
|
||||
|
||||
-- Returns one page of saved multi-page highlight
|
||||
@@ -2039,6 +2043,7 @@ function ReaderHighlight:getSavedExtendedHighlightPage(highlight, page, index)
|
||||
datetime = highlight.datetime,
|
||||
drawer = highlight.drawer,
|
||||
text = highlight.text,
|
||||
note = highlight.note,
|
||||
page = highlight.page,
|
||||
pos0 = highlight.ext[page].pos0,
|
||||
pos1 = highlight.ext[page].pos1,
|
||||
|
||||
Reference in New Issue
Block a user