Skip to content

Commit

Permalink
KeyboardShortcuts: Change delete shortcut to platformAlt + Backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Dec 23, 2024
1 parent e7975b3 commit 019e6b0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
10 changes: 2 additions & 8 deletions packages/block-editor/src/components/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e-test-utils-playwright/src/page-utils/keycodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: () => [],
};
3 changes: 2 additions & 1 deletion 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' | '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
Expand Down Expand Up @@ -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 ],
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( 'shift+delete' );
await pageUtils.pressKeys( 'platformAlt+backspace' );

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( '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
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( '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();
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( 'shift+delete' );
await pageUtils.pressKeys( 'platformAlt+backspace' );

// Ensure the last block was removed.
await expect.poll( editor.getBlocks ).toMatchObject( [

Check failure on line 140 in test/e2e/specs/editor/various/block-deletion.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-deletion.spec.js:108:2 › Block deletion › deleting the last block via the keyboard shortcut

1) [chromium] › editor/various/block-deletion.spec.js:108:2 › Block deletion › deleting the last block via the keyboard shortcut Error: expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 @@ -5,10 +5,10 @@ }, "name": "core/paragraph", }, Object { "attributes": Object { - "content": "Second", + "content": "SecondThird", }, "name": "core/paragraph", }, ] Call Log: - Timeout 5000ms exceeded while waiting on the predicate 138 | 139 | // Ensure the last block was removed. > 140 | await expect.poll( editor.getBlocks ).toMatchObject( [ | ^ 141 | { name: 'core/paragraph', attributes: { content: 'First' } }, 142 | { name: 'core/paragraph', attributes: { content: 'Second' } }, 143 | ] ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-deletion.spec.js:140:3

Check failure on line 140 in test/e2e/specs/editor/various/block-deletion.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-deletion.spec.js:108:2 › Block deletion › deleting the last block via the keyboard shortcut

1) [chromium] › editor/various/block-deletion.spec.js:108:2 › Block deletion › deleting the last block via the keyboard shortcut Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 @@ -5,10 +5,10 @@ }, "name": "core/paragraph", }, Object { "attributes": Object { - "content": "Second", + "content": "SecondThird", }, "name": "core/paragraph", }, ] Call Log: - Timeout 5000ms exceeded while waiting on the predicate 138 | 139 | // Ensure the last block was removed. > 140 | await expect.poll( editor.getBlocks ).toMatchObject( [ | ^ 141 | { name: 'core/paragraph', attributes: { content: 'First' } }, 142 | { name: 'core/paragraph', attributes: { content: 'Second' } }, 143 | ] ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-deletion.spec.js:140:3

Check failure on line 140 in test/e2e/specs/editor/various/block-deletion.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-deletion.spec.js:108:2 › Block deletion › deleting the last block via the keyboard shortcut

1) [chromium] › editor/various/block-deletion.spec.js:108:2 › Block deletion › deleting the last block via the keyboard shortcut Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 @@ -5,10 +5,10 @@ }, "name": "core/paragraph", }, Object { "attributes": Object { - "content": "Second", + "content": "SecondThird", }, "name": "core/paragraph", }, ] Call Log: - Timeout 5000ms exceeded while waiting on the predicate 138 | 139 | // Ensure the last block was removed. > 140 | await expect.poll( editor.getBlocks ).toMatchObject( [ | ^ 141 | { name: 'core/paragraph', attributes: { content: 'First' } }, 142 | { name: 'core/paragraph', attributes: { content: 'Second' } }, 143 | ] ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-deletion.spec.js:140:3
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( 'shift+delete' );
await pageUtils.pressKeys( 'platformAlt+backspace' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
Expand Down
16 changes: 10 additions & 6 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( 'shift+delete' );
await pageUtils.pressKeys( 'shift+delete' );
await pageUtils.pressKeys( 'platformAlt+backspace' );
await pageUtils.pressKeys( 'platformAlt+backspace' );
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( 'shift+delete' );
await pageUtils.pressKeys( 'platformAlt+backspace' );
await expect
.poll(
listViewUtils.getBlocksWithA11yAttributes,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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,
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( 'shift+delete' );
await pageUtils.pressKeys( 'platformAlt+backspace' );

// 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( 'shift+delete' );
await pageUtils.pressKeys( 'platformAlt+backspace' );
await widgetsScreen.saveWidgets();

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

Check failure on line 579 in test/e2e/specs/widgets/editing-widgets.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 6

[chromium] › widgets/editing-widgets.spec.js:543:2 › Widgets screen › Allows widget deletion to be undone

2) [chromium] › widgets/editing-widgets.spec.js:543:2 › Widgets screen › Allows widget deletion to be undone Error: expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 Object { "sidebar-1": Array [ Object { "attributes": Object { - "content": "First Paragraph", + "content": "First ParagraphSecond Paragraph", }, "name": "core/paragraph", }, ], } Call Log: - Timeout 5000ms exceeded while waiting on the predicate 577 | await widgetsScreen.saveWidgets(); 578 | > 579 | await expect.poll( widgetsScreen.getWidgetAreaBlocks ).toMatchObject( { | ^ 580 | 'sidebar-1': [ 581 | { 582 | name: 'core/paragraph', at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/widgets/editing-widgets.spec.js:579:3

Check failure on line 579 in test/e2e/specs/widgets/editing-widgets.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 6

[chromium] › widgets/editing-widgets.spec.js:543:2 › Widgets screen › Allows widget deletion to be undone

2) [chromium] › widgets/editing-widgets.spec.js:543:2 › Widgets screen › Allows widget deletion to be undone Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 Object { "sidebar-1": Array [ Object { "attributes": Object { - "content": "First Paragraph", + "content": "First ParagraphSecond Paragraph", }, "name": "core/paragraph", }, ], } Call Log: - Timeout 5000ms exceeded while waiting on the predicate 577 | await widgetsScreen.saveWidgets(); 578 | > 579 | await expect.poll( widgetsScreen.getWidgetAreaBlocks ).toMatchObject( { | ^ 580 | 'sidebar-1': [ 581 | { 582 | name: 'core/paragraph', at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/widgets/editing-widgets.spec.js:579:3

Check failure on line 579 in test/e2e/specs/widgets/editing-widgets.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 6

[chromium] › widgets/editing-widgets.spec.js:543:2 › Widgets screen › Allows widget deletion to be undone

2) [chromium] › widgets/editing-widgets.spec.js:543:2 › Widgets screen › Allows widget deletion to be undone Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 Object { "sidebar-1": Array [ Object { "attributes": Object { - "content": "First Paragraph", + "content": "First ParagraphSecond Paragraph", }, "name": "core/paragraph", }, ], } Call Log: - Timeout 5000ms exceeded while waiting on the predicate 577 | await widgetsScreen.saveWidgets(); 578 | > 579 | await expect.poll( widgetsScreen.getWidgetAreaBlocks ).toMatchObject( { | ^ 580 | 'sidebar-1': [ 581 | { 582 | name: 'core/paragraph', at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/widgets/editing-widgets.spec.js:579:3
Expand Down

0 comments on commit 019e6b0

Please sign in to comment.