Skip to content

Commit

Permalink
Fixed bad page count when center is in-between pages
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Mar 26, 2024
1 parent 00d32ed commit a201488
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/presentation/readingPage/DocumentNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a201488

Please sign in to comment.