diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js index 462d94f40089c4..696b097757d335 100644 --- a/packages/block-editor/src/components/block-switcher/index.js +++ b/packages/block-editor/src/components/block-switcher/index.js @@ -29,7 +29,7 @@ import PatternTransformationsMenu from './pattern-transformations-menu'; import useBlockDisplayTitle from '../block-title/use-block-display-title'; export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => { - const { replaceBlocks } = useDispatch( blockEditorStore ); + const { replaceBlocks, multiSelect } = useDispatch( blockEditorStore ); const blockInformation = useBlockDisplayInformation( blocks[ 0 ].clientId ); const { possibleBlockTransformations, @@ -89,12 +89,27 @@ export const BlockSwitcherDropdownMenu = ( { clientIds, blocks } ) => { const isReusable = blocks.length === 1 && isReusableBlock( blocks[ 0 ] ); const isTemplate = blocks.length === 1 && isTemplatePart( blocks[ 0 ] ); + function selectForMultipleBlocks( insertedBlocks ) { + if ( insertedBlocks.length > 1 ) { + multiSelect( + insertedBlocks[ 0 ].clientId, + insertedBlocks[ insertedBlocks.length - 1 ].clientId + ); + } + } + // Simple block tranformation based on the `Block Transforms` API. - const onBlockTransform = ( name ) => - replaceBlocks( clientIds, switchToBlockType( blocks, name ) ); + function onBlockTransform( name ) { + const newBlocks = switchToBlockType( blocks, name ); + replaceBlocks( clientIds, newBlocks ); + selectForMultipleBlocks( newBlocks ); + } + // Pattern transformation through the `Patterns` API. - const onPatternTransform = ( transformedBlocks ) => + function onPatternTransform( transformedBlocks ) { replaceBlocks( clientIds, transformedBlocks ); + selectForMultipleBlocks( transformedBlocks ); + } /** * The `isTemplate` check is a stopgap solution here. diff --git a/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-1-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-1-chromium.txt new file mode 100644 index 00000000000000..cbf68836cabedb --- /dev/null +++ b/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-1-chromium.txt @@ -0,0 +1,7 @@ + +

1

+ + + +

2

+ \ No newline at end of file diff --git a/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-2-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-2-chromium.txt new file mode 100644 index 00000000000000..2b3650ed64426e --- /dev/null +++ b/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-2-chromium.txt @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-3-chromium.txt b/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-3-chromium.txt new file mode 100644 index 00000000000000..2b3650ed64426e --- /dev/null +++ b/test/e2e/specs/editor/blocks/__snapshots__/List-selects-all-transformed-output-3-chromium.txt @@ -0,0 +1,9 @@ + + + \ 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 3e5b79cc60c8ed..daa23241a4e8e9 100644 --- a/test/e2e/specs/editor/blocks/list.spec.js +++ b/test/e2e/specs/editor/blocks/list.spec.js @@ -1231,4 +1231,28 @@ test.describe( 'List', () => { expect( await editor.getEditedPostContent() ).toMatchSnapshot(); } ); + + test( 'selects all transformed output', async ( { editor, page } ) => { + await editor.insertBlock( { + name: 'core/list', + innerBlocks: [ + { name: 'core/list-item', attributes: { content: '1' } }, + { name: 'core/list-item', attributes: { content: '2' } }, + ], + } ); + + await editor.selectBlocks( + page.locator( 'role=document[name="Block: List"i]' ) + ); + + await page.getByRole( 'button', { name: 'List' } ).click(); + await page.getByRole( 'menuitem', { name: 'Paragraph' } ).click(); + + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + + await page.getByRole( 'button', { name: 'Paragraph' } ).click(); + await page.getByRole( 'menuitem', { name: 'List' } ).click(); + + expect( await editor.getEditedPostContent() ).toMatchSnapshot(); + } ); } );