From b502227761d76ff2b5751637d820543c8c31ebb7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 17 Jan 2024 17:25:59 +0100 Subject: [PATCH 1/2] Block Hooks: Do not remove toggle if hooked block is present elsewhere --- packages/block-editor/src/hooks/block-hooks.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/block-editor/src/hooks/block-hooks.js b/packages/block-editor/src/hooks/block-hooks.js index f9d7026e48545f..52e71837f275cc 100644 --- a/packages/block-editor/src/hooks/block-hooks.js +++ b/packages/block-editor/src/hooks/block-hooks.js @@ -96,13 +96,8 @@ function BlockHooksControlPure( { name, clientId } ) { } // If no hooked block was found in any of its designated locations, - // but it exists elsewhere in the block tree, we consider it manually inserted. - // In this case, we take note and will remove the corresponding toggle from the - // block inspector panel. - return { - ...clientIds, - [ block.name ]: false, - }; + // we set the toggle to disabled. + return clientIds; }, {} ); @@ -118,13 +113,7 @@ function BlockHooksControlPure( { name, clientId } ) { const { insertBlock, removeBlock } = useDispatch( blockEditorStore ); - // Remove toggle if block isn't present in the designated location but elsewhere in the block tree. - const hookedBlocksForCurrentBlockIfNotPresentElsewhere = - hookedBlocksForCurrentBlock?.filter( - ( block ) => hookedBlockClientIds?.[ block.name ] !== false - ); - - if ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) { + if ( ! hookedBlocksForCurrentBlock.length ) { return null; } From 028cc9f0dc7c44ceb5a2a5fd6905431ea1d4cb09 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 22 Jan 2024 11:27:50 +0100 Subject: [PATCH 2/2] Update comment wording --- packages/block-editor/src/hooks/block-hooks.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/block-editor/src/hooks/block-hooks.js b/packages/block-editor/src/hooks/block-hooks.js index 52e71837f275cc..1e0b8e894d2067 100644 --- a/packages/block-editor/src/hooks/block-hooks.js +++ b/packages/block-editor/src/hooks/block-hooks.js @@ -55,8 +55,7 @@ function BlockHooksControlPure( { name, clientId } ) { const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce( ( clientIds, block ) => { // If the block doesn't exist anywhere in the block tree, - // we know that we have to display the toggle for it, and set - // it to disabled. + // we know that we have to set the toggle to disabled. if ( getGlobalBlockCount( block.name ) === 0 ) { return clientIds; }