Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
getMultiSelectedBlocksEndClientId,
getPreviousBlockClientId,
getNextBlockClientId,
isNavigationMode,
} = useSelect( blockEditorStore );
const {
selectBlock,
Expand Down Expand Up @@ -157,7 +158,10 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
selectedBlockClientId;
}
const startingBlockClientId = hasBlockMovingClientId();

if ( isEscape && isNavigationMode() ) {
clearSelectedBlock();
event.preventDefault();
}
if ( isEscape && startingBlockClientId && ! event.defaultPrevented ) {
setBlockMovingClientId( null );
event.preventDefault();
Expand Down
22 changes: 21 additions & 1 deletion packages/e2e-tests/specs/editor/various/writing-flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

const getActiveBlockName = async () =>
page.evaluate(
() => wp.data.select( 'core/block-editor' ).getSelectedBlock().name
() => wp.data.select( 'core/block-editor' ).getSelectedBlock()?.name
);

const addParagraphsAndColumnsDemo = async () => {
Expand Down Expand Up @@ -630,4 +630,24 @@ describe( 'Writing Flow', () => {
)
).toBe( 'Table' );
} );

it( 'Should unselect all blocks when hitting double escape', async () => {
// Add demo content.
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Random Paragraph' );

// Select a block.
let activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );

// First escape enters navigaiton mode.
await page.keyboard.press( 'Escape' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( 'core/paragraph' );

// Second escape unselects the blocks.
await page.keyboard.press( 'Escape' );
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( undefined );
} );
} );