Skip to content

Writing Flow: Fix ⌘ + ↑/↓ to move cursor to document start/end#78925

Open
Mustafabharmal wants to merge 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/cmd-arrow-document-navigation
Open

Writing Flow: Fix ⌘ + ↑/↓ to move cursor to document start/end#78925
Mustafabharmal wants to merge 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/cmd-arrow-document-navigation

Conversation

@Mustafabharmal

Copy link
Copy Markdown
Contributor

What?

⌘ + ↑ / ⌘ + ↓ on macOS is a common convention to move the cursor to the very start or end of the document. In Gutenberg, this shortcut was not working correctly — it only moved the caret to the top/bottom of the current block, not the first/last block in the document.
Closes #78919.

Why?

The useArrowNav hook in the writing-flow intercepts vertical arrow key presses when the caret is at a block edge and moves focus to the adjacent block. However, it never handled the special case of metaKey + vertical arrow. This allowed the browser's default behaviour to run, which only moves within the current contenteditable element.

How?

  • Added a getEdgeTabbable( containerElement, isReverse ) helper function that finds the absolute first or last tabbable element in the writing-flow container using the same candidate criteria as getClosestTabbable.
  • In onKeyDown, added a new branch: when metaKey && isVertical && !keepCaretInsideBlock, we call getEdgeTabbable to get the target and placeCaretAtVerticalEdge to position the cursor, then preventDefault() to skip the browser's native handling.

Testing Instructions

  1. Open a post in the Gutenberg editor.
  2. Add several paragraph blocks with content.
  3. Click somewhere in a middle block.
  4. Press ⌘ + ↑ — cursor should jump to the beginning of the first block.
  5. Press ⌘ + ↓ — cursor should jump to the end of the last block.

Screenshots or screencast

Before:

+.+.Before.Fix.mov

After:

Testing.+.+.After.Fix.mov

@Mustafabharmal Mustafabharmal requested a review from ellatrix as a code owner June 3, 2026 20:10
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org>
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd + arrow up or down does not moves to start / end of the the document

1 participant