Skip to content

Commit

Permalink
Editor: Unify the region navigation keyboard shortcuts (#60907)
Browse files Browse the repository at this point in the history
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
3 people committed Apr 25, 2024
1 parent 3a38dd8 commit 664148e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 96 deletions.
20 changes: 10 additions & 10 deletions docs/reference-guides/data/data-core-keyboard-shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ExampleComponent = () => {
const allShortcutKeyCombinations = useSelect(
( select ) =>
select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
'core/edit-post/next-region'
'core/editor/next-region'
),
[]
);
Expand Down Expand Up @@ -77,7 +77,7 @@ const ExampleComponent = () => {
const allShortcutRawKeyCombinations = useSelect(
( select ) =>
select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
'core/edit-post/next-region'
'core/editor/next-region'
),
[]
);
Expand Down Expand Up @@ -168,7 +168,7 @@ const ExampleComponent = () => {
const shortcutAliases = useSelect(
( select ) =>
select( keyboardShortcutsStore ).getShortcutAliases(
'core/edit-post/next-region'
'core/editor/next-region'
),
[]
);
Expand Down Expand Up @@ -219,7 +219,7 @@ const ExampleComponent = () => {
const shortcutDescription = useSelect(
( select ) =>
select( keyboardShortcutsStore ).getShortcutDescription(
'core/edit-post/next-region'
'core/editor/next-region'
),
[]
);
Expand Down Expand Up @@ -256,7 +256,7 @@ const ExampleComponent = () => {
const { character, modifier } = useSelect(
( select ) =>
select( keyboardShortcutsStore ).getShortcutKeyCombination(
'core/edit-post/next-region'
'core/editor/next-region'
),
[]
);
Expand Down Expand Up @@ -302,16 +302,16 @@ const ExampleComponent = () => {
const { display, raw, ariaLabel } = useSelect( ( select ) => {
return {
display: select( keyboardShortcutsStore ).getShortcutRepresentation(
'core/edit-post/next-region'
'core/editor/next-region'
),
raw: select( keyboardShortcutsStore ).getShortcutRepresentation(
'core/edit-post/next-region',
'core/editor/next-region',
'raw'
),
ariaLabel: select(
keyboardShortcutsStore
).getShortcutRepresentation(
'core/edit-post/next-region',
'core/editor/next-region',
'ariaLabel'
),
};
Expand Down Expand Up @@ -410,13 +410,13 @@ const ExampleComponent = () => {
const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );

useEffect( () => {
unregisterShortcut( 'core/edit-post/next-region' );
unregisterShortcut( 'core/editor/next-region' );
}, [] );

const shortcut = useSelect(
( select ) =>
select( keyboardShortcutsStore ).getShortcutKeyCombination(
'core/edit-post/next-region'
'core/editor/next-region'
),
[]
);
Expand Down
36 changes: 0 additions & 36 deletions packages/edit-post/src/components/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,6 @@ function KeyboardShortcuts() {
character: 'f',
},
} );

registerShortcut( {
name: 'core/edit-post/next-region',
category: 'global',
description: __( 'Navigate to the next part of the editor.' ),
keyCombination: {
modifier: 'ctrl',
character: '`',
},
aliases: [
{
modifier: 'access',
character: 'n',
},
],
} );

registerShortcut( {
name: 'core/edit-post/previous-region',
category: 'global',
description: __( 'Navigate to the previous part of the editor.' ),
keyCombination: {
modifier: 'ctrlShift',
character: '`',
},
aliases: [
{
modifier: 'access',
character: 'p',
},
{
modifier: 'ctrlShift',
character: '~',
},
],
} );
}, [] );

useShortcut( 'core/edit-post/toggle-fullscreen', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ function Layout( { initialPost } ) {
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
previousShortcut: select(
keyboardShortcutsStore
).getAllShortcutKeyCombinations( 'core/edit-post/previous-region' ),
).getAllShortcutKeyCombinations( 'core/editor/previous-region' ),
nextShortcut: select(
keyboardShortcutsStore
).getAllShortcutKeyCombinations( 'core/edit-post/next-region' ),
).getAllShortcutKeyCombinations( 'core/editor/next-region' ),
showIconLabels: get( 'core', 'showIconLabels' ),
isDistractionFree: get( 'core', 'distractionFree' ),
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
Expand Down
36 changes: 0 additions & 36 deletions packages/edit-site/src/components/keyboard-shortcuts/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,6 @@ function KeyboardShortcutsRegister() {
character: 's',
},
} );

registerShortcut( {
name: 'core/edit-site/next-region',
category: 'global',
description: __( 'Navigate to the next part of the editor.' ),
keyCombination: {
modifier: 'ctrl',
character: '`',
},
aliases: [
{
modifier: 'access',
character: 'n',
},
],
} );

registerShortcut( {
name: 'core/edit-site/previous-region',
category: 'global',
description: __( 'Navigate to the previous part of the editor.' ),
keyCombination: {
modifier: 'ctrlShift',
character: '`',
},
aliases: [
{
modifier: 'access',
character: 'p',
},
{
modifier: 'ctrlShift',
character: '~',
},
],
} );
}, [ registerShortcut ] );

return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ export default function Layout() {
return {
canvasMode: getCanvasMode(),
previousShortcut: getAllShortcutKeyCombinations(
'core/edit-site/previous-region'
'core/editor/previous-region'
),
nextShortcut: getAllShortcutKeyCombinations(
'core/edit-site/next-region'
'core/editor/next-region'
),
hasFixedToolbar: select( preferencesStore ).get(
'core',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,42 @@ function EditorKeyboardShortcutsRegister() {
character: 'h',
},
} );

registerShortcut( {
name: 'core/editor/next-region',
category: 'global',
description: __( 'Navigate to the next part of the editor.' ),
keyCombination: {
modifier: 'ctrl',
character: '`',
},
aliases: [
{
modifier: 'access',
character: 'n',
},
],
} );

registerShortcut( {
name: 'core/editor/previous-region',
category: 'global',
description: __( 'Navigate to the previous part of the editor.' ),
keyCombination: {
modifier: 'ctrlShift',
character: '`',
},
aliases: [
{
modifier: 'access',
character: 'p',
},
{
modifier: 'ctrlShift',
character: '~',
},
],
} );
}, [ registerShortcut ] );

return <BlockEditorKeyboardShortcuts.Register />;
Expand Down
4 changes: 2 additions & 2 deletions packages/keyboard-shortcuts/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ export function registerShortcut( {
* const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
*
* useEffect( () => {
* unregisterShortcut( 'core/edit-post/next-region' );
* unregisterShortcut( 'core/editor/next-region' );
* }, [] );
*
* const shortcut = useSelect(
* ( select ) =>
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
* 'core/edit-post/next-region'
* 'core/editor/next-region'
* ),
* []
* );
Expand Down
16 changes: 8 additions & 8 deletions packages/keyboard-shortcuts/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function getKeyCombinationRepresentation( shortcut, representation ) {
* const {character, modifier} = useSelect(
* ( select ) =>
* select( keyboardShortcutsStore ).getShortcutKeyCombination(
* 'core/edit-post/next-region'
* 'core/editor/next-region'
* ),
* []
* );
Expand Down Expand Up @@ -117,9 +117,9 @@ export function getShortcutKeyCombination( state, name ) {
* const {display, raw, ariaLabel} = useSelect(
* ( select ) =>{
* return {
* display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region' ),
* raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region','raw' ),
* ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/edit-post/next-region', 'ariaLabel')
* display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),
* raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),
* ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')
* }
* },
* []
Expand Down Expand Up @@ -161,7 +161,7 @@ export function getShortcutRepresentation(
* const ExampleComponent = () => {
* const shortcutDescription = useSelect(
* ( select ) =>
* select( keyboardShortcutsStore ).getShortcutDescription( 'core/edit-post/next-region' ),
* select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),
* []
* );
*
Expand Down Expand Up @@ -194,7 +194,7 @@ export function getShortcutDescription( state, name ) {
* const shortcutAliases = useSelect(
* ( select ) =>
* select( keyboardShortcutsStore ).getShortcutAliases(
* 'core/edit-post/next-region'
* 'core/editor/next-region'
* ),
* []
* );
Expand Down Expand Up @@ -247,7 +247,7 @@ export function getShortcutAliases( state, name ) {
* const allShortcutKeyCombinations = useSelect(
* ( select ) =>
* select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
* 'core/edit-post/next-region'
* 'core/editor/next-region'
* ),
* []
* );
Expand Down Expand Up @@ -307,7 +307,7 @@ export const getAllShortcutKeyCombinations = createSelector(
* const allShortcutRawKeyCombinations = useSelect(
* ( select ) =>
* select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
* 'core/edit-post/next-region'
* 'core/editor/next-region'
* ),
* []
* );
Expand Down

1 comment on commit 664148e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 664148e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8827705578
📝 Reported issues:

Please sign in to comment.