Update readerannotation.lua

reviewable/pr11563/r12
hius07 2 months ago committed by GitHub
parent 0ffc497bff
commit 9b5984c14c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -10,7 +10,7 @@ local ReaderAnnotation = WidgetContainer:extend{
-- build, read, save -- build, read, save
function ReaderAnnotation:buildAnnotation(bm, highlights, init) function ReaderAnnotation:buildAnnotation(bm, highlights, init)
-- bm - corresponding bookmark, highlights - all highlights -- bm: associated single bookmark ; highlights: tables with all highlights
local note = bm.text local note = bm.text
if note == "" then if note == "" then
note = nil note = nil
@ -22,8 +22,7 @@ function ReaderAnnotation:buildAnnotation(bm, highlights, init)
note = nil note = nil
end end
if chapter == nil then if chapter == nil then
local pn_or_xp = (self.ui.rolling and bm.pos0) and bm.pos0 or bm.page chapter = self.ui.toc:getTocTitleByPage(bm.page)
chapter = self.ui.toc:getTocTitleByPage(pn_or_xp)
end end
pageno = self.ui.paging and bm.page or self.document:getPageFromXPointer(bm.page) pageno = self.ui.paging and bm.page or self.document:getPageFromXPointer(bm.page)
end end
@ -112,20 +111,20 @@ function ReaderAnnotation:onReadSettings(config)
else -- first run else -- first run
if self.ui.rolling then if self.ui.rolling then
self.ui:registerPostInitCallback(function() self.ui:registerPostInitCallback(function()
self:createAnnotations(config) self:migrateToAnnotations(config)
end) end)
else else
self:createAnnotations(config) self:migrateToAnnotations(config)
end end
end end
end end
function ReaderAnnotation:createAnnotations(config) function ReaderAnnotation:migrateToAnnotations(config)
local bookmarks = config:readSetting("bookmarks") or {} local bookmarks = config:readSetting("bookmarks") or {}
local highlights = config:readSetting("highlight") or {} local highlights = config:readSetting("highlight") or {}
if config:hasNot("highlights_imported") then if config:hasNot("highlights_imported") then
-- old bookmarks were not created along the highlights -- before 2014, saved highlights were not added to bookmarks when they were created.
for page, hls in pairs(highlights) do for page, hls in pairs(highlights) do
for _, hl in ipairs(hls) do for _, hl in ipairs(hls) do
local hl_page = self.ui.paging and page or hl.pos0 local hl_page = self.ui.paging and page or hl.pos0
@ -200,7 +199,7 @@ function ReaderAnnotation:createAnnotations(config)
end end
function ReaderAnnotation:onDocumentRerendered() function ReaderAnnotation:onDocumentRerendered()
self.update = true self.needs_update = true
end end
function ReaderAnnotation:onCloseDocument() function ReaderAnnotation:onCloseDocument()
@ -215,11 +214,11 @@ end
-- items handling -- items handling
function ReaderAnnotation:updatePageNumbers() function ReaderAnnotation:updatePageNumbers()
if self.update then -- triggered by ReaderRolling on document layout change if self.needs_update and self.ui.rolling then -- triggered by ReaderRolling on document layout change
for _, item in ipairs(self.annotations) do for _, item in ipairs(self.annotations) do
item.pageno = self.document:getPageFromXPointer(item.page) item.pageno = self.document:getPageFromXPointer(item.page)
end end
self.update = nil self.needs_update = nil
end end
end end

Loading…
Cancel
Save