Skip to content

Commit

Permalink
Double escape unselects all blocks (#36945)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored and noisysocks committed Nov 30, 2021
1 parent ea2bd81 commit 9c9778c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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
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 @@ -626,4 +626,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 );
} );
} );

0 comments on commit 9c9778c

Please sign in to comment.