Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing Flow: Allow Escape key to deselect blocks and selection during multiselection #48904

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function BlockTools( {
insertAfterBlock,
insertBeforeBlock,
clearSelectedBlock,
selectBlock,
moveBlocksUp,
moveBlocksDown,
} = useDispatch( blockEditorStore );
Expand Down Expand Up @@ -108,7 +109,15 @@ export default function BlockTools( {
const clientIds = getSelectedBlockClientIds();
if ( clientIds.length ) {
event.preventDefault();
clearSelectedBlock();

// If there is more than one block selected, select the first
// block so that focus is directed back to the beginning of the selection.
// In effect, to the user this feels like deselecting the multi-selection.
if ( clientIds.length > 1 ) {
selectBlock( clientIds[ 0 ] );
} else {
clearSelectedBlock();
}
event.target.ownerDocument.defaultView
.getSelection()
.removeAllRanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function useTabNav() {
return;
}

if ( event.keyCode === ESCAPE ) {
if ( event.keyCode === ESCAPE && ! hasMultiSelection() ) {
event.preventDefault();
setNavigationMode( true );
return;
Expand Down