From 8cdf4d54482df39073da6187cf9178f6e61a70ab Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Thu, 24 Oct 2024 12:30:48 +0300 Subject: [PATCH] Zoom out: Add keyboard shortcut in block editor --- .../block-editor/src/components/block-tools/index.js | 8 ++++++++ .../src/components/keyboard-shortcuts/index.js | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/block-editor/src/components/block-tools/index.js b/packages/block-editor/src/components/block-tools/index.js index 700b345be20274..99d0da46b0252e 100644 --- a/packages/block-editor/src/components/block-tools/index.js +++ b/packages/block-editor/src/components/block-tools/index.js @@ -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..df64cdabdf0263 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: __( 'Enter or exit zoom out.' ), + keyCombination: { + modifier: 'primaryShift', + character: 'z', + }, + } ); }, [ registerShortcut ] ); return null;