diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index fd9e0d71646b7e..9b45803404931b 100644 --- a/packages/block-editor/src/components/inserter/index.js +++ b/packages/block-editor/src/components/inserter/index.js @@ -183,14 +183,11 @@ export default compose( [ getBlockRootClientId, hasInserterItems, __experimentalGetAllowedBlocks, - getBlockSelectionEnd, } = select( 'core/block-editor' ); const { getBlockVariations } = select( 'core/blocks' ); rootClientId = - rootClientId || - getBlockRootClientId( clientId || getBlockSelectionEnd() ) || - undefined; + rootClientId || getBlockRootClientId( clientId ) || undefined; const allowedBlocks = __experimentalGetAllowedBlocks( rootClientId ); diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/adding-blocks.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/adding-blocks.test.js.snap index b8160cb3842efc..9f59353093c042 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/adding-blocks.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/adding-blocks.test.js.snap @@ -52,3 +52,15 @@ Foo lines preserved[/myshortcode] " `; + +exports[`adding blocks inserts blocks at root level when using the root appender while selection is in an inner block 1`] = ` +" +
+
1.1
+
+ + + +

2

+" +`; diff --git a/packages/e2e-tests/specs/editor/various/adding-blocks.test.js b/packages/e2e-tests/specs/editor/various/adding-blocks.test.js index d8fcdd41554cc5..aab95bc526917c 100644 --- a/packages/e2e-tests/specs/editor/various/adding-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/adding-blocks.test.js @@ -190,4 +190,31 @@ describe( 'adding blocks', () => { 'block-editor-inserter__toggle' ); } ); + + // Check for regression of https://github.com/WordPress/gutenberg/issues/23263 + it( 'inserts blocks at root level when using the root appender while selection is in an inner block', async () => { + await insertBlock( 'Buttons' ); + await page.keyboard.type( '1.1' ); + + // After inserting the Buttons block the inner button block should be selected. + const selectedButtonBlocks = await page.$$( + '.wp-block-button.is-selected' + ); + expect( selectedButtonBlocks.length ).toBe( 1 ); + + // Specifically click the root container appender. + await page.click( + '.block-editor-block-list__layout.is-root-container > .block-list-appender .block-editor-inserter__toggle' + ); + + // Insert a paragraph block. + await page.waitForSelector( '.block-editor-inserter__search-input' ); + await page.keyboard.type( 'Paragraph' ); + await page.click( '.editor-block-list-item-paragraph' ); + await page.keyboard.type( '2' ); + + // The snapshot should show a buttons block followed by a paragraph. + // The buttons block should contain a single button. + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); } );