From 1736a08efdcc77a2fa9d2006df6da060789a64d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= <4710635+ellatrix@users.noreply.github.com> Date: Tue, 11 Oct 2022 13:00:52 +0200 Subject: [PATCH] List v2: fix selection when creating paragraph from empty list item (#44864) --- .../inner-blocks/use-inner-block-template-sync.js | 5 +++-- ...st-can-be-exited-to-selected-paragraph-1-chromium.txt | 9 +++++++++ test/e2e/specs/editor/blocks/list.spec.js | 9 +++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/e2e/specs/editor/blocks/__snapshots__/List-can-be-exited-to-selected-paragraph-1-chromium.txt 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(); + } ); } );