{{ message }}
Repository navigation
fix(muya): select the document when Select All's cached caret block was removed by undo (#5387) - #5425
Merged
Conversation
…as removed by undo (#5387) Undoing the first edit after a file loads restores no caret, because that undo entry has no selection. When the undo removed the paragraph holding the caret, the DOM caret ends up on the editor container, so `selectAll` fell back to the cached anchor block, which was the removed paragraph, and threw `Cannot destructure property 'path' of 'this.parent' as it is null.` before selecting anything. Typing then inserted at the caret and Backspace deleted nothing. `selectAll` now only grows a selection inside a block that is still in the document; otherwise it selects the whole document. Undo still does not move the caret. Fixes #5387 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Enter + typing, Undo and Select All in a real browser, then typing or Backspace replaces the whole document without page errors. Co-Authored-By: Claude Opus 5 (1M context) <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.

Summary
After undoing a new paragraph as the first edit since the file loaded, Edit > Select All (or Cmd+A) selected nothing and logged
Cannot destructure property 'path' of 'this.parent' as it is null.Typing then inserted at the caret instead of replacing the document (a one-line fileawas saved asaX), and Backspace deleted nothing. Select All now selects the whole document in that state.Steps to reproduce
Desktop app, v0.20.0-rc.3 or a develop build.
a. Make no other edits.a, press Enter and typeb.bline disappears.X, File > Save → the file isaXand the console shows the error above.With
a, a blank line andc, the file is saved asa, a blank line,Xc.Root cause
Historyrecords each undo entry's selection from the previous edit, so the first edit group after load is stored withselection: null._restoreSelection(null), which returns without placing a caret. Removing thebparagraph leaves the DOM caret on the editor container, and the cached selection still points at the removed paragraph.Selection.selectAllreads the live DOM selection, getsnull, and falls back to the cached anchor block. Reading that block'spaththrows, because its paragraph no longer has a parent.A separate edit before step 2 (for example typing
zand waiting a second) gives the undo entry a selection, and Select All works.Fix
selectAllonly grows a selection inside a block that is still in the document (outMostBlockis non-null, the same check #5384 uses for block commands). Otherwise it falls through to selecting the whole document.This fix is limited to Select All. Undo and redo still do not place a caret, same as #5384.
Behaviour notes
a/cvariant: the first Select All after the undo selects the whole document. Without the undo it first selects the current paragraph, but after this undo the caret is not in any paragraph.aX,Xc), same as develop.Test plan
Unit:
src/selection/__tests__/selectAllAfterUndo5387.spec.ts(aanda/c, real undo with thenullundo-entry precondition pinned). Fails on develop with the reported error, passes with the fix.e2e:
e2e/tests/editing/select-all-after-undo-5387.spec.ts(Enter + type, Undo, Select All, then typeXor Backspace, no page errors). Fails on develop, passes 30/30 with--repeat-each=5in Chromium and WebKit.pnpm -C packages/muya test: 247 files, 1812 tests passed.lint:types,check-circular, eslint on the changed files (e2e spec with--no-ignore).Desktop app driven by Playwright with a fresh
--user-data-dirand Edit menu items clicked from the application menu, packaged v0.20.0-rc.3 vs abuild:unpackof this branch:a: Undo, Select All, typeXaX+ 1 errorX, 0 errorsa: Undo, Select All ×3, typeXaX+ 3 errorsX, 0 errorsa: Undo, Select All, Backspacea+ 1 errora/c: Undo, Select All ×2, typeXa, blank line,Xc+ 2 errorsX, 0 errorsa: Undo, Cmd+A, typeXaX+ 1 errorX, 0 errorsWindows / Linux, Firefox
Fixes #5387
🤖 Generated with Claude Code