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 5eff89609f6d8c..1b81069c44f3dc 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 @@ -40,7 +40,7 @@ export default function useInnerBlockTemplateSync( templateLock, templateInsertUpdatesSelection ) { - const { getSelectedBlocksInitialCaretPosition } = + const { getSelectedBlocksInitialCaretPosition, isBlockSelected } = useSelect( blockEditorStore ); const { replaceInnerBlocks } = useDispatch( blockEditorStore ); const innerBlocks = useSelect( @@ -86,7 +86,8 @@ export default function useInnerBlockTemplateSync( nextBlocks, currentInnerBlocks.length === 0 && templateInsertUpdatesSelection && - nextBlocks.length !== 0, + nextBlocks.length !== 0 && + isBlockSelected( clientId ), // 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. diff --git a/test/e2e/specs/editor/blocks/__snapshots__/List-can-be-exited-to-selected-paragraph-1-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/List-can-be-exited-to-selected-paragraph-1-chromium.txt new file mode 100644 index 00000000000000..468d73c8514442 --- /dev/null +++ b/test/e2e/specs/editor/blocks/__snapshots__/List-can-be-exited-to-selected-paragraph-1-chromium.txt @@ -0,0 +1,9 @@ + + + + + +

1

+ \ No newline at end of file diff --git a/test/e2e/specs/editor/blocks/list.spec.js b/test/e2e/specs/editor/blocks/list.spec.js index c0133cc73629ac..ad63edc6fbaf0d 100644 --- a/test/e2e/specs/editor/blocks/list.spec.js +++ b/test/e2e/specs/editor/blocks/list.spec.js @@ -1225,4 +1225,13 @@ test.describe( 'List', () => { ` ); } ); + + test( 'can be exited to selected paragraph', async ( { editor, page } ) => { + await page.click( 'role=button[name="Add default block"i]' ); + await page.keyboard.type( '* ' ); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( '1' ); + + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + } ); } );