From a201488d2f32213086fb0b20b549b33fdcccdd88 Mon Sep 17 00:00:00 2001 From: DavidLazarescu Date: Tue, 26 Mar 2024 21:02:37 +0100 Subject: [PATCH] Fixed bad page count when center is in-between pages --- src/presentation/readingPage/DocumentNavigation.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/presentation/readingPage/DocumentNavigation.js b/src/presentation/readingPage/DocumentNavigation.js index 56d093b22..7f9e36c71 100644 --- a/src/presentation/readingPage/DocumentNavigation.js +++ b/src/presentation/readingPage/DocumentNavigation.js @@ -26,10 +26,17 @@ function handleWheel(wheel) { // Calculate the current page and update the document. function updateCurrentPageCounter() { // A new page starts if it is over the middle of the screen (vertically). + let middleOfScreen = pageView.contentY + pageView.height / 2 let pageNumber = pageView.indexAt(pageView.currentItem.width / 2, - pageView.contentY + pageView.height / 2) + middleOfScreen) + + // If the middle of the screen is in the free space between two pages, take the lower one + if (pageNumber === -1) { + let pageSpacing = pageView.getPageSpacing(root.bookController.zoom) + pageNumber = pageView.indexAt(pageView.currentItem.width / 2, + middleOfScreen + pageSpacing) + } - // let pageNumber = Math.floor(currentPos / pageHeight) if (pageNumber !== root.bookController.currentPage) root.bookController.currentPage = pageNumber }