From aaa5aee91df13f21a3ea01bfcee572b88a846596 Mon Sep 17 00:00:00 2001 From: Yogesh Bhutkar Date: Tue, 11 Feb 2025 16:23:38 +0530 Subject: [PATCH] Update keyboard shortcuts to use `primaryShift+backspace` for block deletion (#69074) * update keyboard shortcuts to use `primaryShift+backspace` for block deletion * fix: simplify condition to skip delete listener for delete key combo Unlinked contributors: Czab1, tjarrettveracode. Co-authored-by: yogeshbhutkar Co-authored-by: t-hamano Co-authored-by: jarekmorawski Co-authored-by: Mamaduka Co-authored-by: talldan Co-authored-by: jasmussen Co-authored-by: dcalhoun --- .../src/components/keyboard-shortcuts/index.js | 2 +- .../rich-text/event-listeners/delete.js | 6 +++--- test/e2e/specs/editor/blocks/navigation.spec.js | 10 +++++----- .../specs/editor/various/block-deletion.spec.js | 2 +- .../specs/editor/various/block-locking.spec.js | 2 +- test/e2e/specs/editor/various/list-view.spec.js | 16 ++++++++++------ test/e2e/specs/site-editor/template-part.spec.js | 2 +- test/e2e/specs/widgets/editing-widgets.spec.js | 2 +- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/block-editor/src/components/keyboard-shortcuts/index.js b/packages/block-editor/src/components/keyboard-shortcuts/index.js index fcc2cea4043753..4d368e6c1d0ab4 100644 --- a/packages/block-editor/src/components/keyboard-shortcuts/index.js +++ b/packages/block-editor/src/components/keyboard-shortcuts/index.js @@ -29,7 +29,7 @@ function KeyboardShortcutsRegister() { category: 'block', description: __( 'Remove the selected block(s).' ), keyCombination: { - modifier: 'shift', + modifier: 'primaryShift', character: 'backspace', }, } ); diff --git a/packages/block-editor/src/components/rich-text/event-listeners/delete.js b/packages/block-editor/src/components/rich-text/event-listeners/delete.js index 8373ca3c9f72ae..ad59ae8a70d322 100644 --- a/packages/block-editor/src/components/rich-text/event-listeners/delete.js +++ b/packages/block-editor/src/components/rich-text/event-listeners/delete.js @@ -6,7 +6,7 @@ import { isCollapsed, isEmpty } from '@wordpress/rich-text'; export default ( props ) => ( element ) => { function onKeyDown( event ) { - const { keyCode, shiftKey } = event; + const { keyCode, shiftKey, ctrlKey, metaKey } = event; if ( event.defaultPrevented ) { return; @@ -30,8 +30,8 @@ export default ( props ) => ( element ) => { return; } - // Exclude shift+backspace as they are shortcuts for deleting blocks. - if ( shiftKey ) { + // Exclude (command|ctrl)+shift+backspace as they are shortcuts for deleting blocks. + if ( shiftKey && ( ctrlKey || metaKey ) ) { return; } diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index 769e30c99dab36..c04ef78811e069 100644 --- a/test/e2e/specs/editor/blocks/navigation.spec.js +++ b/test/e2e/specs/editor/blocks/navigation.spec.js @@ -276,7 +276,7 @@ test.describe( 'Navigation block', () => { await pageUtils.pressKeys( 'ArrowDown' ); // remove the child link - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); const submenuBlock2 = editor.canvas.getByRole( 'document', { name: 'Block: Submenu', @@ -494,7 +494,7 @@ test.describe( 'Navigation block', () => { await pageUtils.pressKeys( 'ArrowDown', { times: 4 } ); await navigation.checkLabelFocus( 'wordpress.org' ); // Delete the nav link - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); // Focus moved to sibling await navigation.checkLabelFocus( 'Dog' ); // Add a link back so we can delete the first submenu link and see if focus returns to the parent submenu item @@ -507,15 +507,15 @@ test.describe( 'Navigation block', () => { await pageUtils.pressKeys( 'ArrowUp', { times: 2 } ); await navigation.checkLabelFocus( 'Dog' ); // Delete the nav link - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await pageUtils.pressKeys( 'ArrowDown' ); // Focus moved to parent submenu item await navigation.checkLabelFocus( 'example.com' ); // Deleting this should move focus to the sibling item - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await navigation.checkLabelFocus( 'Cat' ); // Deleting with no more siblings should focus the navigation block again - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await expect( navBlock ).toBeFocused(); // Wait until the nav block inserter is visible before we continue. await expect( navBlockInserter ).toBeVisible(); diff --git a/test/e2e/specs/editor/various/block-deletion.spec.js b/test/e2e/specs/editor/various/block-deletion.spec.js index 5e4ead97c986fd..f90923c6dc3829 100644 --- a/test/e2e/specs/editor/various/block-deletion.spec.js +++ b/test/e2e/specs/editor/various/block-deletion.spec.js @@ -134,7 +134,7 @@ test.describe( 'Block deletion', () => { ).toBeFocused(); // Remove the current paragraph via dedicated keyboard shortcut. - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); // Ensure the last block was removed. await expect.poll( editor.getBlocks ).toMatchObject( [ diff --git a/test/e2e/specs/editor/various/block-locking.spec.js b/test/e2e/specs/editor/various/block-locking.spec.js index b31fc9e2cd1402..cf81fede4c31d5 100644 --- a/test/e2e/specs/editor/various/block-locking.spec.js +++ b/test/e2e/specs/editor/various/block-locking.spec.js @@ -133,7 +133,7 @@ test.describe( 'Block Locking', () => { ).toBeVisible(); await paragraph.click(); - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await expect.poll( editor.getBlocks ).toMatchObject( [ { diff --git a/test/e2e/specs/editor/various/list-view.spec.js b/test/e2e/specs/editor/various/list-view.spec.js index 17f82ce1b76e36..988683c8d11aa3 100644 --- a/test/e2e/specs/editor/various/list-view.spec.js +++ b/test/e2e/specs/editor/various/list-view.spec.js @@ -812,8 +812,8 @@ test.describe( 'List View', () => { // Delete remaining blocks. // Keyboard shortcut should also work. - await pageUtils.pressKeys( 'shift+Backspace' ); - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await expect .poll( listViewUtils.getBlocksWithA11yAttributes, @@ -845,7 +845,7 @@ test.describe( 'List View', () => { { name: 'core/heading', selected: false }, ] ); - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await expect .poll( listViewUtils.getBlocksWithA11yAttributes, @@ -868,7 +868,11 @@ test.describe( 'List View', () => { .getByRole( 'gridcell', { name: 'File' } ) .getByRole( 'link' ) .focus(); - for ( const keys of [ 'Delete', 'Backspace', 'shift+Backspace' ] ) { + for ( const keys of [ + 'Delete', + 'Backspace', + 'primaryShift+Backspace', + ] ) { await pageUtils.pressKeys( keys ); await expect .poll( @@ -1136,7 +1140,7 @@ test.describe( 'List View', () => { optionsForFileMenu, 'Pressing Space should also open the menu dropdown' ).toBeVisible(); - await pageUtils.pressKeys( 'shift+Backspace' ); // Keyboard shortcut for Delete. + await pageUtils.pressKeys( 'primaryShift+Backspace' ); // Keyboard shortcut for Delete. await expect .poll( listViewUtils.getBlocksWithA11yAttributes, @@ -1156,7 +1160,7 @@ test.describe( 'List View', () => { optionsForFileMenu.getByRole( 'menuitem', { name: 'Delete' } ), 'The delete menu item should be hidden for locked blocks' ).toBeHidden(); - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await expect .poll( listViewUtils.getBlocksWithA11yAttributes, diff --git a/test/e2e/specs/site-editor/template-part.spec.js b/test/e2e/specs/site-editor/template-part.spec.js index 9d5c0ca05b0d9c..d3feeb866619a2 100644 --- a/test/e2e/specs/site-editor/template-part.spec.js +++ b/test/e2e/specs/site-editor/template-part.spec.js @@ -375,7 +375,7 @@ test.describe( 'Template Part', () => { await editor.selectBlocks( siteTitle ); // Remove the default site title block. - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); // Insert a group block with a Site Title block inside. await editor.insertBlock( { diff --git a/test/e2e/specs/widgets/editing-widgets.spec.js b/test/e2e/specs/widgets/editing-widgets.spec.js index f4d160f8a36db3..648b04d3e202b2 100644 --- a/test/e2e/specs/widgets/editing-widgets.spec.js +++ b/test/e2e/specs/widgets/editing-widgets.spec.js @@ -573,7 +573,7 @@ test.describe( 'Widgets screen', () => { .getByRole( 'document', { name: 'Block: Paragraph' } ) .filter( { hasText: 'Second Paragraph' } ) .focus(); - await pageUtils.pressKeys( 'shift+Backspace' ); + await pageUtils.pressKeys( 'primaryShift+Backspace' ); await widgetsScreen.saveWidgets(); await expect.poll( widgetsScreen.getWidgetAreaBlocks ).toMatchObject( {