Backup and restore bookmarks/highlights: fix logic (#8473)

reviewable/pr8474/r1
hius07 2 years ago committed by GitHub
parent a2d95f5a3f
commit 1c9e21389d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -268,17 +268,26 @@ function ReaderBookmark:onReadSettings(config)
-- Bookmark formats in crengine and mupdf are incompatible.
-- Backup bookmarks when the document is opened with incompatible engine.
if #self.bookmarks > 0 then
if self.ui.rolling and type(self.bookmarks[1].page) == "number" then
local bookmarks_type = type(self.bookmarks[1].page)
if self.ui.rolling and bookmarks_type == "number" then
config:saveSetting("bookmarks_paging", self.bookmarks)
self.bookmarks = config:readSetting("bookmarks_rolling", {})
config:saveSetting("bookmarks", self.bookmarks)
config:delSetting("bookmarks_rolling")
elseif self.ui.paging and type(self.bookmarks[1].page) == "string" then
elseif self.ui.paging and bookmarks_type == "string" then
config:saveSetting("bookmarks_rolling", self.bookmarks)
self.bookmarks = config:readSetting("bookmarks_paging", {})
config:saveSetting("bookmarks", self.bookmarks)
config:delSetting("bookmarks_paging")
end
else
if self.ui.rolling and config:has("bookmarks_rolling") then
self.bookmarks = config:readSetting("bookmarks_rolling")
config:delSetting("bookmarks_rolling")
elseif self.ui.paging and config:has("bookmarks_paging") then
self.bookmarks = config:readSetting("bookmarks_paging")
config:delSetting("bookmarks_paging")
end
end
-- need to do this after initialization because checking xpointer
-- may cause segfaults before credocuments are inited.

@ -792,18 +792,28 @@ function ReaderView:onReadSettings(config)
self.highlight.saved = config:readSetting("highlight", {})
-- Highlight formats in crengine and mupdf are incompatible.
-- Backup highlights when the document is opened with incompatible engine.
if #self.highlight.saved > 0 then
if self.ui.rolling and type(self.highlight.saved[1][1].pos0) == "table" then
local _page, page_highlights = next(self.highlight.saved)
if page_highlights then
local highlight_type = type(page_highlights[1].pos0)
if self.ui.rolling and highlight_type == "table" then
config:saveSetting("highlight_paging", self.highlight.saved)
self.highlight.saved = config:readSetting("highlight_rolling", {})
config:saveSetting("highlight", self.highlight.saved)
config:delSetting("highlight_rolling")
elseif self.ui.paging and type(self.highlight.saved[1][1].pos0) == "string" then
elseif self.ui.paging and highlight_type == "string" then
config:saveSetting("highlight_rolling", self.highlight.saved)
self.highlight.saved = config:readSetting("highlight_paging", {})
config:saveSetting("highlight", self.highlight.saved)
config:delSetting("highlight_paging")
end
else
if self.ui.rolling and config:has("highlight_rolling") then
self.highlight.saved = config:readSetting("highlight_rolling")
config:delSetting("highlight_rolling")
elseif self.ui.paging and config:has("highlight_paging") then
self.highlight.saved = config:readSetting("highlight_paging")
config:delSetting("highlight_paging")
end
end
self.inverse_reading_order = config:isTrue("inverse_reading_order") or G_reader_settings:isTrue("inverse_reading_order")
self.page_overlap_enable = config:isTrue("show_overlap_enable") or G_reader_settings:isTrue("page_overlap_enable") or DSHOWOVERLAP

Loading…
Cancel
Save