Skip to content

Commit

Permalink
List View: Add a special case for shortcuts coming from modals
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed May 13, 2024
1 parent e147f7d commit fec0e10
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { BACKSPACE, DELETE } from '@wordpress/keycodes';
import isShallowEqual from '@wordpress/is-shallow-equal';
import { __unstableUseShortcutEventMatch as useShortcutEventMatch } from '@wordpress/keyboard-shortcuts';
import { speak } from '@wordpress/a11y';
import { isTextField } from '@wordpress/dom';

/**
* Internal dependencies
Expand Down Expand Up @@ -182,10 +181,7 @@ function ListViewBlock( {
return;
}

// Retain the default behavior for text fields.
if ( isTextField( event.target ) ) {
return;
}
const isDeleteKey = [ BACKSPACE, DELETE ].includes( event.keyCode );

// If multiple blocks are selected, deselect all blocks when the user
// presses the escape key.
Expand All @@ -197,10 +193,15 @@ function ListViewBlock( {
event.preventDefault();
selectBlock( event, undefined );
} else if (
event.keyCode === BACKSPACE ||
event.keyCode === DELETE ||
isDeleteKey ||
isMatch( 'core/block-editor/remove', event )
) {
// Do not handle single-key block deletion shortcuts when events come from modals;
// retain the default behavior for these keys.
if ( isDeleteKey && event.target.closest( '[role=dialog]' ) ) {
return;
}

const {
blocksToUpdate: blocksToDelete,
firstBlockClientId,
Expand Down

0 comments on commit fec0e10

Please sign in to comment.