From efa08f666b6b4dd4bfb53625318be2450bf26ea5 Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 24 Oct 2024 12:16:37 +0300 Subject: [PATCH] Zoom out: Add keyboard shortcut in block editor --- .../block-editor/src/components/block-tools/index.js | 10 +++++++++- .../src/components/keyboard-shortcuts/index.js | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-tools/index.js b/packages/block-editor/src/components/block-tools/index.js index 700b345be20274..13031f4fcc3ffc 100644 --- a/packages/block-editor/src/components/block-tools/index.js +++ b/packages/block-editor/src/components/block-tools/index.js @@ -70,7 +70,7 @@ export default function BlockTools( { getSelectedBlockClientIds, getBlockRootClientId, isGroupable, - } = useSelect( blockEditorStore ); + } = unlock( useSelect( blockEditorStore ) ); const { getGroupingBlockName } = useSelect( blocksStore ); const { showEmptyBlockSideInserter, showBlockToolbarPopover } = useShowBlockTools(); @@ -85,6 +85,8 @@ export default function BlockTools( { moveBlocksUp, moveBlocksDown, expandBlock, + setZoomLevel, + resetZoomLevel, } = unlock( useDispatch( blockEditorStore ) ); function onKeyDown( event ) { @@ -175,6 +177,12 @@ export default function BlockTools( { replaceBlocks( clientIds, newBlocks ); speak( __( 'Selected blocks are grouped.' ) ); } + } else if ( isMatch( 'core/block-editor/zoom', event ) ) { + if ( isZoomOutMode ) { + resetZoomLevel(); + } else { + setZoomLevel( 'auto-scaled' ); + } } } const blockToolbarRef = usePopoverScroll( __unstableContentRef ); diff --git a/packages/block-editor/src/components/keyboard-shortcuts/index.js b/packages/block-editor/src/components/keyboard-shortcuts/index.js index 9b838446469229..dbaaef8bc4d07b 100644 --- a/packages/block-editor/src/components/keyboard-shortcuts/index.js +++ b/packages/block-editor/src/components/keyboard-shortcuts/index.js @@ -155,6 +155,15 @@ function KeyboardShortcutsRegister() { character: 'g', }, } ); + registerShortcut( { + name: 'core/block-editor/zoom', + category: 'global', + description: __( 'Toggle zoom out.' ), + keyCombination: { + modifier: 'primaryShift', + character: 'z', + }, + } ); }, [ registerShortcut ] ); return null;