Skip to content

DOCX: keep the scroll position when annotations change (0.1.4) - #7

Merged
JSv4 merged 1 commit into
mainfrom
docx-keep-scroll
Nov 26, 2026
Merged

JSv4 merged 1 commit into
mainfrom
docx-keep-scroll

Conversation

@JSv4

@JSv4 JSv4 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

The bug

In a DOCX, removing an annotation while scrolled into the document sent the view back to the top. So did adding one, a highlight, a text selection and a zoom: anything that projects or lays the document out again.

Cause

docxodus/react's usePagination sets innerHTML on its element and then lays the pages out. Between the two the document is no taller than its stylesheets, the pagination engine's measuring forces a layout, and the browser clamps the root's scroll position to 0. Nothing is remounted.

Fix

src/docx/DocxView.tsx: just before each new layout of a document that is already laid out, the scope element takes its current size as its minimum size, and gives it up when that layout has succeeded or failed. The scroll position is never clamped, so no scroll event fires either.

A new zoom now keeps the scroll offset in pixels instead of going to the top.

Test

ct-tests/docx.ct.tsx: scrolls to the bottom, removes an annotation, then adds it back, and expects the scroll position unchanged each time. It failed before the fix (2508 px to 0).

Version 0.1.4.

docxodus' pagination empties its element before it writes the pages again,
so for that moment the document was no taller than its stylesheets and the
root scrolled back to the start. Every new projection did it: an annotation
added or removed, a highlight, a text selection, and a new zoom.

The scope element now keeps the size it has from just before each new
layout until that layout has succeeded or failed.

Version 0.1.4.
@JSv4
JSv4 merged commit 1063d84 into main Nov 26, 2026
6 checks passed
@JSv4
JSv4 deleted the docx-keep-scroll branch November 26, 2026 15:41
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.

1 participant