Repository navigation
DOCX: keep the scroll position when annotations change (0.1.4) - #7
Merged
Merged
Conversation
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.
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
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'susePaginationsetsinnerHTMLon 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.