From 019e6b044d1c5f714867b85fc9e5da3f60281425 Mon Sep 17 00:00:00 2001 From: yogeshbhutkar Date: Mon, 23 Dec 2024 14:28:27 +0530 Subject: [PATCH] KeyboardShortcuts: Change delete shortcut to platformAlt + Backspace --- .../src/components/keyboard-shortcuts/index.js | 10 ++-------- .../src/page-utils/keycodes.ts | 5 +++-- packages/keycodes/src/index.js | 3 ++- 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 +- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/block-editor/src/components/keyboard-shortcuts/index.js b/packages/block-editor/src/components/keyboard-shortcuts/index.js index 8e66a8fb65c2b9..a967e6f673b546 100644 --- a/packages/block-editor/src/components/keyboard-shortcuts/index.js +++ b/packages/block-editor/src/components/keyboard-shortcuts/index.js @@ -29,15 +29,9 @@ function KeyboardShortcutsRegister() { category: 'block', description: __( 'Remove the selected block(s).' ), keyCombination: { - modifier: 'shift', - character: 'delete', + modifier: 'platformAlt', + character: 'backspace', }, - aliases: [ - { - modifier: 'shift', - character: 'backspace', - }, - ], } ); registerShortcut( { diff --git a/packages/e2e-test-utils-playwright/src/page-utils/keycodes.ts b/packages/e2e-test-utils-playwright/src/page-utils/keycodes.ts index f2ae2d186c7a72..a5cca37f02dac7 100644 --- a/packages/e2e-test-utils-playwright/src/page-utils/keycodes.ts +++ b/packages/e2e-test-utils-playwright/src/page-utils/keycodes.ts @@ -26,7 +26,7 @@ export const SHIFT = 'shift'; /** * Keycode for DELETE key. */ -export const DELETE = 'delete'; +export const BACKSPACE = 'backspace'; /** * Object that contains functions that return the available modifier @@ -44,11 +44,12 @@ export const modifiers: Record< secondary: ( _isApple ) => _isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ], access: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ), + platformAlt: ( _isApple ) => ( _isApple() ? [ CTRL ] : [ ALT ] ), ctrl: () => [ CTRL ], alt: () => [ ALT ], ctrlShift: () => [ CTRL, SHIFT ], shift: () => [ SHIFT ], shiftAlt: () => [ SHIFT, ALT ], - delete: () => [ DELETE ], + backspace: () => [ BACKSPACE ], undefined: () => [], }; diff --git a/packages/keycodes/src/index.js b/packages/keycodes/src/index.js index b6df5e3f4a2145..85d526921b824e 100644 --- a/packages/keycodes/src/index.js +++ b/packages/keycodes/src/index.js @@ -21,7 +21,7 @@ import { isAppleOS } from './platform'; /** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */ -/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */ +/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'platformAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */ /** * An object of handler functions for each of the possible modifier @@ -188,6 +188,7 @@ export const modifiers = { secondary: ( _isApple ) => _isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ], access: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ), + platformAlt: ( _isApple ) => ( _isApple() ? [ CTRL ] : [ ALT ] ), ctrl: () => [ CTRL ], alt: () => [ ALT ], ctrlShift: () => [ CTRL, SHIFT ], diff --git a/test/e2e/specs/editor/blocks/navigation.spec.js b/test/e2e/specs/editor/blocks/navigation.spec.js index 7daab2f6ecc120..ae588691969437 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+delete' ); + await pageUtils.pressKeys( 'platformAlt+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+delete' ); + await pageUtils.pressKeys( 'platformAlt+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+delete' ); + await pageUtils.pressKeys( 'platformAlt+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+delete' ); + await pageUtils.pressKeys( 'platformAlt+backspace' ); await navigation.checkLabelFocus( 'Cat' ); // Deleting with no more siblings should focus the navigation block again - await pageUtils.pressKeys( 'shift+delete' ); + await pageUtils.pressKeys( 'platformAlt+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 fb7d898d1e5dee..50d591e244693f 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+delete' ); + await pageUtils.pressKeys( 'platformAlt+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 5b6e3e6946b565..882dcabc2669a5 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+delete' ); + await pageUtils.pressKeys( 'platformAlt+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 52febba89ac398..e28fc7a5c7c632 100644 --- a/test/e2e/specs/editor/various/list-view.spec.js +++ b/test/e2e/specs/editor/various/list-view.spec.js @@ -809,8 +809,8 @@ test.describe( 'List View', () => { // Delete remaining blocks. // Keyboard shortcut should also work. - await pageUtils.pressKeys( 'shift+delete' ); - await pageUtils.pressKeys( 'shift+delete' ); + await pageUtils.pressKeys( 'platformAlt+backspace' ); + await pageUtils.pressKeys( 'platformAlt+backspace' ); await expect .poll( listViewUtils.getBlocksWithA11yAttributes, @@ -842,7 +842,7 @@ test.describe( 'List View', () => { { name: 'core/heading', selected: false }, ] ); - await pageUtils.pressKeys( 'shift+delete' ); + await pageUtils.pressKeys( 'platformAlt+backspace' ); await expect .poll( listViewUtils.getBlocksWithA11yAttributes, @@ -865,7 +865,11 @@ test.describe( 'List View', () => { .getByRole( 'gridcell', { name: 'File' } ) .getByRole( 'link' ) .focus(); - for ( const keys of [ 'Delete', 'Backspace', 'shift+delete' ] ) { + for ( const keys of [ + 'Delete', + 'Backspace', + 'platformAlt+backspace', + ] ) { await pageUtils.pressKeys( keys ); await expect .poll( @@ -1133,7 +1137,7 @@ test.describe( 'List View', () => { optionsForFileMenu, 'Pressing Space should also open the menu dropdown' ).toBeVisible(); - await pageUtils.pressKeys( 'shift+delete' ); // Keyboard shortcut for Delete. + await pageUtils.pressKeys( 'platformAlt+backspace' ); // Keyboard shortcut for Delete. await expect .poll( listViewUtils.getBlocksWithA11yAttributes, @@ -1153,7 +1157,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+delete' ); + await pageUtils.pressKeys( 'platformAlt+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 abab6cf2210274..6c721f6d045506 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+delete' ); + await pageUtils.pressKeys( 'platformAlt+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 a287330a26a90c..8ebec07248a865 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+delete' ); + await pageUtils.pressKeys( 'platformAlt+backspace' ); await widgetsScreen.saveWidgets(); await expect.poll( widgetsScreen.getWidgetAreaBlocks ).toMatchObject( {