From 83488001b2c2fc511fbff4a4955fb2a513dafa4c Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Tue, 16 Jul 2024 22:59:09 -0700 Subject: [PATCH] Zoom Out: fix crash due to absence of selected block --- .../components/block-tools/use-show-block-tools.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/use-show-block-tools.js b/packages/block-editor/src/components/block-tools/use-show-block-tools.js index 83757790d11ea2..70a0b9f53a3421 100644 --- a/packages/block-editor/src/components/block-tools/use-show-block-tools.js +++ b/packages/block-editor/src/components/block-tools/use-show-block-tools.js @@ -29,10 +29,11 @@ export function useShowBlockTools() { const clientId = getSelectedBlockClientId() || getFirstMultiSelectedBlockClientId(); - const block = getBlock( clientId ) || { name: '', attributes: {} }; + const block = getBlock( clientId ); const editorMode = __unstableGetEditorMode(); - const hasSelectedBlock = clientId && block?.name; - const isEmptyDefaultBlock = isUnmodifiedDefaultBlock( block ); + const hasSelectedBlock = !! clientId && !! block; + const isEmptyDefaultBlock = + hasSelectedBlock && isUnmodifiedDefaultBlock( block ); const _showEmptyBlockSideInserter = clientId && ! isTyping() && @@ -43,8 +44,9 @@ export function useShowBlockTools() { ! hasMultiSelection() && editorMode === 'navigation'; + const isZoomOut = editorMode === 'zoom-out'; const _showBlockToolbarPopover = - editorMode !== 'zoom-out' && + ! isZoomOut && ! getSettings().hasFixedToolbar && ! _showEmptyBlockSideInserter && hasSelectedBlock && @@ -57,7 +59,8 @@ export function useShowBlockTools() { ! _showEmptyBlockSideInserter && maybeShowBreadcrumb, showBlockToolbarPopover: _showBlockToolbarPopover, showZoomOutToolbar: - editorMode === 'zoom-out' && + hasSelectedBlock && + isZoomOut && ! _showEmptyBlockSideInserter && ! maybeShowBreadcrumb && ! _showBlockToolbarPopover,