Writing Flow: Fix ⌘ + ↑/↓ to move cursor to document start/end#78925
Writing Flow: Fix ⌘ + ↑/↓ to move cursor to document start/end#78925Mustafabharmal wants to merge 1 commit into
Conversation
|
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.
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. |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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
useArrowNavhook 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 ofmetaKey + vertical arrow. This allowed the browser's default behaviour to run, which only moves within the currentcontenteditableelement.How?
getEdgeTabbable( containerElement, isReverse )helper function that finds the absolute first or last tabbable element in the writing-flow container using the same candidate criteria asgetClosestTabbable.onKeyDown, added a new branch: whenmetaKey && isVertical && !keepCaretInsideBlock, we callgetEdgeTabbableto get the target andplaceCaretAtVerticalEdgeto position the cursor, thenpreventDefault()to skip the browser's native handling.Testing Instructions
⌘ + ↑— cursor should jump to the beginning of the first block.⌘ + ↓— cursor should jump to the end of the last block.Screenshots or screencast
Before:
+.+.Before.Fix.mov
After:
Testing.+.+.After.Fix.mov