Skip to content

Commit

Permalink
KeyboardShortcuts: Update delete shortcut to use primaryShift + Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Dec 23, 2024
1 parent 019e6b0 commit 33542de
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ function KeyboardShortcutsRegister() {
category: 'block',
description: __( 'Remove the selected block(s).' ),
keyCombination: {
modifier: 'platformAlt',
modifier: 'primaryShift',
character: 'backspace',
},
aliases: [
{
modifier: 'primaryShift',
character: 'delete',
},
],
} );

registerShortcut( {
Expand Down
7 changes: 0 additions & 7 deletions packages/e2e-test-utils-playwright/src/page-utils/keycodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ export const COMMAND = 'meta';
*/
export const SHIFT = 'shift';

/**
* Keycode for DELETE key.
*/
export const BACKSPACE = 'backspace';

/**
* Object that contains functions that return the available modifier
* depending on platform.
Expand All @@ -44,12 +39,10 @@ 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 ],
backspace: () => [ BACKSPACE ],
undefined: () => [],
};
3 changes: 1 addition & 2 deletions packages/keycodes/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { isAppleOS } from './platform';

/** @typedef {typeof ALT | CTRL | COMMAND | SHIFT } WPModifierPart */

/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'platformAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */
/** @typedef {'primary' | 'primaryShift' | 'primaryAlt' | 'secondary' | 'access' | 'ctrl' | 'alt' | 'ctrlShift' | 'shift' | 'shiftAlt' | 'undefined'} WPKeycodeModifier */

/**
* An object of handler functions for each of the possible modifier
Expand Down Expand Up @@ -188,7 +188,6 @@ 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 ],
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/specs/editor/blocks/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ test.describe( 'Navigation block', () => {
await pageUtils.pressKeys( 'ArrowDown' );

// remove the child link
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );

const submenuBlock2 = editor.canvas.getByRole( 'document', {
name: 'Block: Submenu',
Expand Down Expand Up @@ -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( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
// 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
Expand All @@ -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( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
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( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
await navigation.checkLabelFocus( 'Cat' );
// Deleting with no more siblings should focus the navigation block again
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
await expect( navBlock ).toBeFocused();
// Wait until the nav block inserter is visible before we continue.
await expect( navBlockInserter ).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/block-deletion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ test.describe( 'Block deletion', () => {
).toBeFocused();

// Remove the current paragraph via dedicated keyboard shortcut.
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );

// Ensure the last block was removed.
await expect.poll( editor.getBlocks ).toMatchObject( [
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/block-locking.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test.describe( 'Block Locking', () => {
).toBeVisible();

await paragraph.click();
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
Expand Down
16 changes: 6 additions & 10 deletions test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ test.describe( 'List View', () => {

// Delete remaining blocks.
// Keyboard shortcut should also work.
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand Down Expand Up @@ -842,7 +842,7 @@ test.describe( 'List View', () => {
{ name: 'core/heading', selected: false },
] );

await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand All @@ -865,11 +865,7 @@ test.describe( 'List View', () => {
.getByRole( 'gridcell', { name: 'File' } )
.getByRole( 'link' )
.focus();
for ( const keys of [
'Delete',
'Backspace',
'platformAlt+backspace',
] ) {
for ( const keys of [ 'Delete', 'Backspace', 'primaryShift+Delete' ] ) {
await pageUtils.pressKeys( keys );
await expect
.poll(
Expand Down Expand Up @@ -1137,7 +1133,7 @@ test.describe( 'List View', () => {
optionsForFileMenu,
'Pressing Space should also open the menu dropdown'
).toBeVisible();
await pageUtils.pressKeys( 'platformAlt+backspace' ); // Keyboard shortcut for Delete.
await pageUtils.pressKeys( 'primaryShift+Delete' ); // Keyboard shortcut for Delete.
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand All @@ -1157,7 +1153,7 @@ test.describe( 'List View', () => {
optionsForFileMenu.getByRole( 'menuitem', { name: 'Delete' } ),
'The delete menu item should be hidden for locked blocks'
).toBeHidden();
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/site-editor/template-part.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ test.describe( 'Template Part', () => {
await editor.selectBlocks( siteTitle );

// Remove the default site title block.
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );

// Insert a group block with a Site Title block inside.
await editor.insertBlock( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/widgets/editing-widgets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ test.describe( 'Widgets screen', () => {
.getByRole( 'document', { name: 'Block: Paragraph' } )
.filter( { hasText: 'Second Paragraph' } )
.focus();
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'primaryShift+Delete' );
await widgetsScreen.saveWidgets();

await expect.poll( widgetsScreen.getWidgetAreaBlocks ).toMatchObject( {
Expand Down

0 comments on commit 33542de

Please sign in to comment.