Skip to content

Commit

Permalink
Editor: Unify the region navigation keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Apr 19, 2024
1 parent ff3afd3 commit 6f07599
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 @@ -62,42 +62,6 @@ function KeyboardShortcuts() {
},
} );

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: '~',
},
],
} );

registerShortcut( {
name: 'core/edit-post/transform-heading-to-paragraph',
category: 'block-library',
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 @@ -180,10 +180,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 @@ -20,42 +20,6 @@ function KeyboardShortcutsRegister() {
},
} );

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( {
name: 'core/edit-site/transform-heading-to-paragraph',
category: 'block-library',
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

0 comments on commit 6f07599

Please sign in to comment.