Skip to content

Commit

Permalink
Revert the initial stop block selection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Sep 8, 2022
1 parent 4f0299b commit 5ea4352
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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()
);
} );
}
Expand Down

0 comments on commit 5ea4352

Please sign in to comment.