Repository navigation
fix(muya): stop ArrowDown from endlessly creating empty paragraphs (#3520) - #4650
Merged
Merged
Conversation
…3520) `arrowHandler` appended a new trailing paragraph whenever ArrowDown was pressed at the end of the last block with no next block — including when the last block was already an empty paragraph. So holding/repeating ArrowDown in an empty document created a new empty paragraph on every keypress. Only append a trailing paragraph when the current (last) block has content; otherwise the caret stays put. Guard the offset computation since the cursor target can now be absent. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Fixes #3520
Problem
In an empty (or trailing-empty) document, pressing ↓ repeatedly created a new empty paragraph on every keypress.
Root cause
Content.arrowHandler(packages/muya/src/block/base/content.ts) appends a trailing paragraph whenever ArrowDown is pressed at the end of the last block and there is no next block — with no check on whether the current block is itself already empty. An empty last paragraph (text = '', caret at offset 0) satisfies the condition, so each ArrowDown appends another empty paragraph. (ThegetCursorYOffsetearly-return doesn't help: an empty single-line paragraph yieldsbottomOffset = 0.)Fix
Append the trailing paragraph only when the current block has content (
this.text.length > 0); otherwise the caret stays put. The offset computation is guarded since the cursor target can now be absent.The existing behavior — ArrowDown at the end of a non-empty last block appends one trailing paragraph — is preserved (covered by an existing test).
Verification
arrowNavigation.spec.ts: new test — ArrowDown in an already-empty trailing paragraph does not create another block (RED→GREEN); the existing non-empty-last-block test still passes.lint:typesclean; ESLint clean (one pre-existingarrowHandlercomplexity warning, unchanged policy).🤖 Generated with Claude Code