From 179743619b8bfc753bf33115c9dc5b3a0120c117 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Fri, 11 Oct 2024 10:12:11 +0200 Subject: [PATCH] Only keep one visible inserter --- .../block-tools/zoom-out-mode-inserters.js | 65 +++++++------------ 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js index c279cb3678202..ac15881c78d8d 100644 --- a/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js +++ b/packages/block-editor/src/components/block-tools/zoom-out-mode-inserters.js @@ -16,30 +16,24 @@ function ZoomOutModeInserters() { const [ isReady, setIsReady ] = useState( false ); const { hasSelection, - insertionPoint, blockOrder, - blockInsertionPointVisible, setInserterIsOpened, sectionRootClientId, selectedBlockClientId, } = useSelect( ( select ) => { const { getSettings, - getInsertionPoint, getBlockOrder, getSelectionStart, getSelectedBlockClientId, getSectionRootClientId, - isBlockInsertionPointVisible, } = unlock( select( blockEditorStore ) ); const root = getSectionRootClientId(); return { hasSelection: !! getSelectionStart().clientId, - insertionPoint: getInsertionPoint(), blockOrder: getBlockOrder( root ), - blockInsertionPointVisible: isBlockInsertionPointVisible(), sectionRootClientId: root, setInserterIsOpened: getSettings().__experimentalSetIsInserterOpened, @@ -64,41 +58,32 @@ function ZoomOutModeInserters() { return null; } - return [ undefined, ...blockOrder ].map( ( clientId, index ) => { - const shouldRenderInsertionPoint = - blockInsertionPointVisible && insertionPoint?.index === index; + const previousClientId = selectedBlockClientId; + const index = blockOrder.findIndex( + ( clientId ) => selectedBlockClientId === clientId + ); + const nextClientId = blockOrder[ index + 1 ]; - const previousClientId = clientId; - const nextClientId = blockOrder[ index ]; - - const isSelected = - selectedBlockClientId === previousClientId || - selectedBlockClientId === nextClientId; - - return ( - - { ! shouldRenderInsertionPoint && isSelected && ( - { - setInserterIsOpened( { - rootClientId: sectionRootClientId, - insertionIndex: index, - tab: 'patterns', - category: 'all', - } ); - showInsertionPoint( sectionRootClientId, index, { - operation: 'insert', - } ); - } } - /> - ) } - - ); - } ); + return ( + + { + setInserterIsOpened( { + rootClientId: sectionRootClientId, + insertionIndex: index, + tab: 'patterns', + category: 'all', + } ); + showInsertionPoint( sectionRootClientId, index, { + operation: 'insert', + } ); + } } + /> + + ); } export default ZoomOutModeInserters;