From 54a0cdd737ec9f529724d0bba4fcd76805c2f8c3 Mon Sep 17 00:00:00 2001 From: poire-z Date: Wed, 22 May 2024 21:25:22 +0200 Subject: [PATCH] ReaderFooter: fix minor issues with pages left & chapter progress When using Reference page numbers, "Pages left" was showing the same info as "Current page", because Reference pages, being strings, couldn't be used for arithmetics. But we can just count the number of items left in the Reference pages array of strings. Also fix edge case with "page progress" with hidden flow when we are before the first chapter with a hidden flow before. --- frontend/apps/reader/modules/readerfooter.lua | 12 +++++++++--- frontend/apps/reader/modules/readerpagemap.lua | 7 +++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 7e4ba7edb..5f187f70d 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -265,9 +265,12 @@ local footerTextGeneratorMap = { if footer.pageno then if footer.ui.pagemap and footer.ui.pagemap:wantsPageLabels() then -- (Page labels might not be numbers) - return ("%s %s / %s"):format(prefix, - footer.ui.pagemap:getCurrentPageLabel(true), - footer.ui.pagemap:getLastPageLabel(true)) + local label, idx, count = footer.ui.pagemap:getCurrentPageLabel(false) -- luacheck: no unused + local remaining = count - idx + if footer.settings.pages_left_includes_current_page then + remaining = remaining + 1 + end + return ("%s %s / %s"):format(prefix, remaining, footer.ui.pagemap:getLastPageLabel(true)) end if footer.ui.document:hasHiddenFlows() then -- i.e., if we are hiding non-linear fragments and there's anything to hide, @@ -2488,6 +2491,9 @@ function ReaderFooter:getChapterProgress(get_percentage, pageno) current = current + 1 else current = pageno + if self.ui.document:hasHiddenFlows() then + current = self.ui.document:getPageNumberInFlow(pageno) + end end local total = self.ui.toc:getChapterPageCount(pageno) or self.pages if get_percentage then diff --git a/frontend/apps/reader/modules/readerpagemap.lua b/frontend/apps/reader/modules/readerpagemap.lua index a2beb6a89..045f4a67b 100644 --- a/frontend/apps/reader/modules/readerpagemap.lua +++ b/frontend/apps/reader/modules/readerpagemap.lua @@ -280,8 +280,11 @@ function ReaderPageMap:getCurrentPageLabel(clean_label) -- For consistency, getPageMapCurrentPageLabel() returns the last page -- label shown in the view if there are more than one (or the previous -- one if there is none). - local label = self.ui.document:getPageMapCurrentPageLabel() - return clean_label and self:cleanPageLabel(label) or label + local label, idx, count = self.ui.document:getPageMapCurrentPageLabel() + if clean_label then + label = self:cleanPageLabel(label) + end + return label, idx, count end function ReaderPageMap:getFirstPageLabel(clean_label)