Scroll to the right page when reading Bottom to Top - #836
Merged
Conversation
The vertical pager hands `v-virtual-scroll` a list of page numbers and reverses that list for bottom-to-top reading, so page 0 becomes the last item. `scrollToIndex` takes an index into that list, but `scrollToPage` passed the page number straight through, so every jump landed on the mirrored page: opening a comic at page 0 scrolled to the last page. Look the page up in `items` rather than repeating the reversal, so this keeps following however that list is built. Top to Bottom is unaffected, where a page number is already its own index; a test pins that too. Page tracking was never wrong. The intersection observer reads the real page number off the element, so only jumping to a page was affected. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
The vertical pager hands
v-virtual-scrolla list of page numbers andreverses that list for bottom-to-top reading, so page 0 becomes the last
item and the last page becomes the first.
scrollToIndextakes an index into that list, butscrollToPagepassed thepage number straight through as if it were one. In Bottom to Top every jump
therefore landed on the mirrored page: opening a comic at page 0 scrolled to
the last page, page 1 of 10 showed page 9, and so on. The offset calculation
clamps rather than erroring, so it failed silently.
Bottom to Top is the only reading direction that is both vertical and
reversed, so it is the only one affected. Top to Bottom was always correct,
because there a page number really is its own index.
Page tracking was never wrong in either direction. The intersection observer
reads the real page number off the element, so only jumping to a page was
affected, not reporting which page you are on.
The fix
Look the page up in
itemsinstead of assuming it is the index. Deriving itfrom the list rather than repeating the reversal means it keeps working
however that list comes to be built.
Testing
Four tests covering both directions, including Top to Bottom as a regression
guard that the common path still maps a page to its own index.
Mutation-checked: restoring the old call fails all three Bottom to Top cases
and leaves the Top to Bottom one green. Suite is 460 passing, lint clean.
Found while answering whether Vuetify 4.2.0's new
scrollToIndexpositionargument could simplify this component. It cannot, and that is unrelated to
this fix, which predates the upgrade.
🤖 Generated with Claude Code