Repository navigation
fix(docx): past the scroll cap, the pages move once and as far as the scroll - #53
Merged
Merged
Conversation
… scroll A document longer than a browser lets a box scroll (12,000,000 px) mapped the scroll position to the place shown by a factor. Every scroll then went that factor too far: the wheel and Page Down skipped pages, the caret brought into view by the browser overshot, and a native scroll moved the pages twice (by the browser, then by the next render). The pages now stay in the scrolled content, drawn an offset higher than they are in the document (ScrollMap, src/react/docx/longscroll.ts): - a step (wheel, keys, the caret, a selection dragged past an edge) leaves the offset alone: the browser moves the pages by itself, pixel for pixel; - a jump to where no page is drawn (the scrollbar's thumb, Home, End) goes where the thumb says; a long scroll that ends on a page that is drawn is the browser's own (focus, scrollIntoView) and is kept pixel for pixel; - at rest, or when the box reaches an end of its range before the document does, the box is put where its thumb belongs and the offset changes by as much, in one frame: nothing moves on screen. A document that grows past the cap while it loads stays where the reader is, and another zoom keeps the place. Fixes #50 Co-Authored-By: Claude Fable 5.2 <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.
Fixes #50.
What was wrong
Past the 12,000,000 px cap the scroll position was mapped to the place shown by a factor (2.8 for the test document: 200 tall pages, as in
e2e/plain.spec.ts). Measured on main:scrollIntoViewof a pageWhy not the sticky wrapper the issue proposes
A wrapper fixed in the box and moved by
-scrollYremoves the two-step move, but every scroll still goesscaletimes as far: the browser scrolls the box by the distance it wants (a line for the caret, a box for Page Down) and the linear map multiplies it.The change
ScrollMap(src/react/docx/longscroll.ts): the pages stay in the scrolled content, drawnoffhigher than they are in the document. The place shown isscrollTop + off.offalone. The browser moves the pages by itself, once, pixel for pixel. No page is repositioned while scrolling.scrollIntoView) and is kept pixel for pixel.offchanges by as much, in one frame: nothing moves on screen. The first and last 1,000,000 px map pixel for pixel, so the ends of the document are the ends of the range.scrollToY/scrollByY.A document no longer than the box scrolls over takes the same path as before: its scroll position is the place.
Also: a document that grows past the cap while it loads stays where the reader is, and another zoom keeps the place.
Tests
test/docx-longscroll.test.ts: the map alone (14 tests).e2e/docx-longscroll.spec.ts(6 tests): wheel and rest, Page Down, steps to the last page through the end of the range, the caret by arrow keys,scrollIntoView, zoom. On main 5 of the 6 fail with the numbers above; the zoom test passes on both and guards what already worked.e2e/plain.spec.tspass.Left as it is
🤖 Generated with Claude Code