From 5ea435263220530310f58ba93c770d0fd58bce67 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 8 Sep 2022 14:31:04 +0100 Subject: [PATCH] Revert the initial stop block selection bug --- .../use-inner-block-template-sync.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/src/components/inner-blocks/use-inner-block-template-sync.js b/packages/block-editor/src/components/inner-blocks/use-inner-block-template-sync.js index a4f5cedc6bb9f4..2277c72fc55692 100644 --- a/packages/block-editor/src/components/inner-blocks/use-inner-block-template-sync.js +++ b/packages/block-editor/src/components/inner-blocks/use-inner-block-template-sync.js @@ -69,13 +69,6 @@ export default function useInnerBlockTemplateSync( template ); - // This ensures the "initialPosition" doesn't change when applying the template - // If we're supposed to focus the block, we'll focus the first inner block - // otherwise, we won't apply any auto-focus. - // This ensures for instance that the focus stays in the inserter when inserting the "buttons" block. - const previousInitialPosition = - getSelectedBlocksInitialCaretPosition(); - if ( ! isEqual( nextBlocks, innerBlocks ) ) { // There's an implicit dependency between useInnerBlockTemplateSync and useNestedSettingsUpdate // The former needs to happen after the latter and since the latter is using microtasks to batch updates (performance optimization), @@ -87,9 +80,12 @@ export default function useInnerBlockTemplateSync( nextBlocks, innerBlocks.length === 0 && templateInsertUpdatesSelection && - nextBlocks.length !== 0 && - previousInitialPosition !== null, - previousInitialPosition + nextBlocks.length !== 0, + // This ensures the "initialPosition" doesn't change when applying the template + // If we're supposed to focus the block, we'll focus the first inner block + // otherwise, we won't apply any auto-focus. + // This ensures for instance that the focus stays in the inserter when inserting the "buttons" block. + getSelectedBlocksInitialCaretPosition() ); } ); }