Repository navigation
fix(muya): ArrowUp at document start moves the caret to offset 0 (#3193) - #4655
Merged
Merged
Conversation
…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]>
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 #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 calledpreventDefault()/stopPropagation()and thenreturned 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.lint:typesclean; ESLint clean (one pre-existingarrowHandlercomplexity warning).🤖 Generated with Claude Code