Skip to content

Commit

Permalink
Zoom out: Add keyboard shortcut in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Oct 24, 2024
1 parent e9fb510 commit badcae7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

/**
* Handles the keyboard shortcuts for the editor.
Expand All @@ -24,7 +25,12 @@ export default function EditorKeyboardShortcuts() {
select( editorStore ).getEditorSettings();
return ! richEditingEnabled || ! codeEditingEnabled;
}, [] );
const { getBlockSelectionStart } = useSelect( blockEditorStore );
const { getBlockSelectionStart, isZoomOut } = unlock(
useSelect( blockEditorStore )
);
const { setZoomLevel, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);
const { getActiveComplementaryArea } = useSelect( interfaceStore );
const { enableComplementaryArea, disableComplementaryArea } =
useDispatch( interfaceStore );
Expand Down Expand Up @@ -118,5 +124,13 @@ export default function EditorKeyboardShortcuts() {
}
} );

useShortcut( 'core/editor/zoom', () => {
if ( isZoomOut() ) {
resetZoomLevel();
} else {
setZoomLevel( 'auto-scaled' );
}
} );

return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ function EditorKeyboardShortcutsRegister() {
},
],
} );

registerShortcut( {
name: 'core/editor/zoom',
category: 'global',
description: __( 'Enter or exit zoom out.' ),
keyCombination: {
modifier: 'primaryShift',
character: 'z',
},
} );
}, [ registerShortcut ] );

return <BlockEditorKeyboardShortcuts.Register />;
Expand Down

0 comments on commit badcae7

Please sign in to comment.