Skip to content

fix(docx): past the scroll cap, the pages move once and as far as the scroll - #53

Merged
pierreneter merged 1 commit into
mainfrom
fix/docx-long-scroll
Nov 23, 2026
Merged

pierreneter merged 1 commit into
mainfrom
fix/docx-long-scroll

Conversation

@pierreneter

Copy link
Copy Markdown
Member

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:

What main With this change
Wheel, 300 px pages move 300 px, then more 300 px, once
Page Down in a 960 px box 2330 px one box
Arrow down past the box edge 97 px for a 36 px line the line
scrollIntoView of a page lands somewhere else shows it

Why not the sticky wrapper the issue proposes

A wrapper fixed in the box and moved by -scrollY removes the two-step move, but every scroll still goes scale times 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, drawn off higher than they are in the document. The place shown is scrollTop + off.

  • A step (wheel, keys, the caret brought into view, a selection dragged past an edge) leaves off alone. The browser moves the pages by itself, once, pixel for pixel. No page is repositioned while scrolling.
  • 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 (150 ms), or when the box reaches an end of its range before the document does, the box is scrolled to where its thumb belongs and off changes 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.
  • Caret, find, outline and comment navigation still go through 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.
  • Chromium and Firefox: this spec and the existing cap test in e2e/plain.spec.ts pass.
  • Full run with this change (Chromium): unit tests and all e2e specs pass.

Left as it is

  • A caret left on a page, the thumb then dragged millions of pixels away: an arrow key makes the browser scroll to a page that is drawn outside the box's range, which it cannot reach. Typing brings the caret's page back, as before.
  • The Code pane's "keep the scroll position" after a rebuild sets the box by ratio once the document reaches the cap; a document that keeps loading after that stays at that place instead of following the ratio.

🤖 Generated with Claude Code

… 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>
@pierreneter
pierreneter merged commit 5ce9005 into main Nov 23, 2026
2 checks passed
@pierreneter
pierreneter deleted the fix/docx-long-scroll branch November 23, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX: past the scroll cap, native and browser scrolls move the pages twice

1 participant