Skip to content

fix(muya): ArrowUp at document start moves the caret to offset 0 (#3193) - #4655

Merged
Jocs merged 2 commits into
developfrom
fix/issue-3193-arrowup-file-start
Jun 23, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/issue-3193-arrowup-file-start

Conversation

@Jocs

@Jocs Jocs commented Jun 23, 2026

Copy link
Copy Markdown
Member

Fixes #3193

Problem

Placing the caret in the middle of the first line of the first paragraph and pressing ↑ did nothing — the caret stayed put. Standard editor behavior is to move the caret to the start of the line.

Root cause

Content.arrowHandler (packages/muya/src/block/base/content.ts): on ArrowUp at the first visual line, it called preventDefault()/stopPropagation() and then returned early when there was no previous block — suppressing the browser's default caret-to-line-start without providing an alternative.

Fix

When there is no previous block, ArrowUp now moves the caret to offset 0 of the current block. A boundary ArrowLeft (offset 0, no previous block) still has nowhere to go and is left to do nothing.

Verification

  • arrowNavigation.spec.ts: new test — ArrowUp from a mid-first-line caret moves to offset 0 (RED→GREEN); existing cross-block up/down navigation tests still pass.
  • Full muya unit suite: 1235 tests pass.
  • lint:types clean; ESLint clean (one pre-existing arrowHandler complexity warning).

🤖 Generated with Claude Code

Jocs and others added 2 commits June 23, 2026 14:27
…fset 0 (#3193)

Pressing ArrowUp on the first visual line of the first block (no previous
block) called preventDefault/stopPropagation and returned without moving the
caret, so the caret stayed put instead of jumping to the start of the line.

When there is no previous block, ArrowUp now moves the caret to offset 0 of
the current block (a boundary ArrowLeft still has nowhere to go and is left
to do nothing).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…3193)

When the caret is already at offset 0 of the first block, ArrowUp has
nowhere to go, but the handler still called setCursor(0, 0, true) — which
unconditionally re-sets the selection (TextSelection.setSelection always
emits selection-change, with no equality check) and re-renders the block's
innerHTML. Guard the re-set with `start.offset !== 0` so a no-op ArrowUp
stays silent. preventDefault is still issued, so the native no-op scroll is
suppressed as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jocs
Jocs merged commit 2267cb2 into develop Jun 23, 2026
7 checks passed
@Jocs
Jocs deleted the fix/issue-3193-arrowup-file-start branch June 23, 2026 09:18
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.

Cursor behaviour when pressing up at the start of a file.

1 participant