Skip to content

fix(muya): stop ArrowDown from endlessly creating empty paragraphs (#3520) - #4650

Merged
Jocs merged 1 commit into
developfrom
fix/issue-3520-arrowdown-endless-paragraph
Jun 23, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/issue-3520-arrowdown-endless-paragraph

Conversation

@Jocs

@Jocs Jocs commented Jun 23, 2026

Copy link
Copy Markdown
Member

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. (The getCursorYOffset early-return doesn't help: an empty single-line paragraph yields bottomOffset = 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.
  • Full muya unit suite: 163 files / 1235 tests pass.
  • lint:types clean; ESLint clean (one pre-existing arrowHandler complexity warning, unchanged policy).

🤖 Generated with Claude Code

…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]>
@Jocs
Jocs merged commit 318a0a3 into develop Jun 23, 2026
7 checks passed
@Jocs
Jocs deleted the fix/issue-3520-arrowdown-endless-paragraph branch June 23, 2026 07:50
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.

MarkText can add new paragraphs endlessly when using a "DOWN" arrow key to move the cursor

1 participant