diff --git a/packages/block-editor/src/components/block-list/use-multi-selection.js b/packages/block-editor/src/components/block-list/use-multi-selection.js index 8505ce7a07556..2d40464f2c0c5 100644 --- a/packages/block-editor/src/components/block-list/use-multi-selection.js +++ b/packages/block-editor/src/components/block-list/use-multi-selection.js @@ -105,8 +105,9 @@ export default function useMultiSelection( ref ) { ); if ( - ! blockNode.contains( startContainer ) || - ! blockNode.contains( endContainer ) + !! blockNode && + ( ! blockNode.contains( startContainer ) || + ! blockNode.contains( endContainer ) ) ) { selection.removeAllRanges(); } @@ -242,17 +243,6 @@ export default function useMultiSelection( ref ) { startClientId.current = clientId; anchorElement.current = document.activeElement; - if ( anchorElement.current ) { - const blockInspector = document.querySelector( - '.block-editor-block-inspector' - ); - if ( - blockInspector && - blockInspector.contains( anchorElement.current ) - ) { - return; - } - } startMultiSelect(); // `onSelectionStart` is called after `mousedown` and `mouseleave` diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/duplicating-blocks.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/duplicating-blocks.test.js.snap new file mode 100644 index 0000000000000..bb8192de22cb9 --- /dev/null +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/duplicating-blocks.test.js.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Duplicating blocks should duplicate blocks using the block settings menu 1`] = ` +" +

Clone me

+ + + +

Clone me

+" +`; + +exports[`Duplicating blocks should duplicate blocks using the keyboard shortcut 1`] = ` +" +

Clone me

+ + + +

Clone me

+" +`; diff --git a/packages/e2e-tests/specs/editor/various/duplicating-blocks.test.js b/packages/e2e-tests/specs/editor/various/duplicating-blocks.test.js new file mode 100644 index 0000000000000..a5aadb7766a79 --- /dev/null +++ b/packages/e2e-tests/specs/editor/various/duplicating-blocks.test.js @@ -0,0 +1,49 @@ +/** + * WordPress dependencies + */ +import { + createNewPost, + insertBlock, + getEditedPostContent, + clickBlockToolbarButton, + pressKeyWithModifier, +} from '@wordpress/e2e-test-utils'; + +describe( 'Duplicating blocks', () => { + beforeEach( async () => { + await createNewPost(); + } ); + + it( 'should duplicate blocks using the block settings menu', async () => { + await insertBlock( 'Paragraph' ); + await page.keyboard.type( 'Clone me' ); + + // Select the test we just typed + // This doesn't do anything but we previously had a duplicationi bug + // When the selection was not collapsed + await pressKeyWithModifier( 'primary', 'a' ); + + await clickBlockToolbarButton( 'More options' ); + const duplicateButton = await page.waitForXPath( + '//button[text()="Duplicate"]' + ); + await duplicateButton.click(); + + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); + + it( 'should duplicate blocks using the keyboard shortcut', async () => { + await insertBlock( 'Paragraph' ); + await page.keyboard.type( 'Clone me' ); + + // Select the test we just typed + // This doesn't do anything but we previously had a duplicationi bug + // When the selection was not collapsed + await pressKeyWithModifier( 'primary', 'a' ); + + // Duplicate using the keyboard shortccut + await pressKeyWithModifier( 'primaryShift', 'd' ); + + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); +} );