Repository navigation
fix(docx): what the reader does while Find or the outline is on its way comes first - #60
Merged
Merged
Conversation
…ay comes first Find and the outline scroll to their target and select it once the scroll has come to rest, some frames later. Nothing stopped that late selection: a reader who pressed Enter in Find, then clicked into the text and typed, could have the match selected again after the click, and the keys typed replaced the word found. - A click, a key or the wheel in the document drops the jump on its way, and so does a newer jump. - At its end, the jump selects its target only while the document's selection is where it was when the jump began (or not in the document): one set since, by the reader or by the host through the DOM, is kept. - No selection is put in a paragraph edited meanwhile: the match's offsets are out of date. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the focus, not the selection Review findings on the late selection of Find and the outline: - The reader who went to a field outside the document (the Find bar's Replace, the toolbar) had the jump land anyway: the selection was no longer in the document and counted as untouched, and the outline's caret took the focus back. The jump now lands only while the focus is where it was when the jump began, or the element that had it is gone (the Find bar closed). A caret set in the text by the host focuses the document, and is kept as before. - This replaces comparing the document's selection, which a collaborator's edit above the caret moved, so the jump did not land though the reader had done nothing. - A query typed on in the Find bar drops the jump to the match of the query before. - A paragraph rebuilt with the same text (a style or a comment mark put on it) no longer stops the jump: its id and text are compared, not the object. The outline compares only which block it is: the caret goes to its start. - The key press that began a jump (a host's shortcut listening before the document) no longer drops it. - A page or a comment shown meanwhile drops the jump, as a newer jump does. - Tests: frames made late can still be cancelled; the document's selection is told from the Find field's; a query typed on and a field gone to are covered (both fail on the version before). Co-Authored-By: Claude Opus 5.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.
Find and the outline scroll to their target, then select it once the scroll has come to rest:
afterScrollruns a few frames later, up to 120 on a slow machine. Nothing stopped that late selection, so it could land after the reader had already put the caret somewhere else.What went wrong
A reader presses Enter in Find, then clicks into the text and types. If the late selection came after the click, the match was selected again and the keys typed replaced the word found. Without Track changes on, the word was gone without a trace. The outline did the same: its late caret took the place of the one just clicked.
This is the cause behind the flaky
e2e/plain.spec.tsin #59, which only makes that test wait for the selection.Fix (
src/react/docx/DocxView.tsx)What the reader does comes first. These drop the jump on its way:
.de-scroll;gotoPage) or a comment shown;Each
afterScrolltakes a number, and a jump runs only while its number is still the latest. The Find bar is outside.de-scroll, so Enter for the next match doesn't drop anything. The key press that began a jump is older than the jump, so a host shortcut listening before the document doesn't drop its own jump.The jump lands only where the reader still is. At its end, the selection is put in place only while the focus is on the element that had it when the jump began, or that element is gone (the Find bar closed). This covers:
A collaborator's edit doesn't move the focus, so it doesn't stop the jump.
No selection in a paragraph whose text changed meanwhile, since the match's offsets were taken before. The paragraph's id and text are compared, so a paragraph rebuilt with the same text (a style, a comment mark) doesn't stop the jump. The outline only checks which block it is, since its caret goes to the block's start.
Closing the Find bar alone doesn't drop the jump: Enter then Escape still leaves the match selected, as when the frames come on time.
Tests
e2e/docx-jump.spec.ts(new), with every animation frame made 1 s late (the last two rows fail on this PR's first version, before the review):NEIGHBOR, typeXYalpha XY omegaselectText)alpha XY omegaplain.spec.ts's Find test on this Mac, 4 runs each: fails 3 times onmainand 2 times with this PR alone. With fix: three flaky tests: Find's late selection in the long document, tracked typing across a second, the big CSV's time #59's wait added it passed 4 of 4.bun test ./test: 1751 pass, 0 failtsc --noEmit: cleanbun test ./e2e: 381 pass, 13 fail on macOS (CI runs Linux):dist/for the four*-builtspecs (bun run build), and the generatedlarge-deck.pptx;mainon this machine (Mac key bindings:Control+c,End,Tabin a slide);plain.spec.ts(the known flaky one) failed once in the full run, while a source file was saved during it. It passed in the two runs that comparedmainwith the fix, and 3 out of 3 times withdocx-jump.spec.ts.🤖 Generated with Claude Code