From e66b26865b4e2b64d516c1ef95cd7d1748a7a941 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Wed, 24 Nov 2021 19:14:13 +0200 Subject: [PATCH] Highlights backup fix (#8479) Fixes opening book with old highlights, when (after deleting the last highlight on a page) empty table of highlights for this page was not deleted. --- frontend/apps/reader/modules/readerview.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 91481a6af..333b61734 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -792,7 +792,15 @@ 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. - local _, page_highlights = next(self.highlight.saved) -- get the first page with highlights + local page, page_highlights + while true do -- remove empty tables for pages without highlights and get the first page with highlights + page, page_highlights = next(self.highlight.saved) + if not page or #page_highlights > 0 then + break -- we're done (there is none, or there is some usable) + else + self.highlight.saved[page] = nil -- clean it up while we're at it, and find another one + end + end if page_highlights then local highlight_type = type(page_highlights[1].pos0) if self.ui.rolling and highlight_type == "table" then