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: Double escape unselects all blocks #36945

Merged
merged 1 commit into from Nov 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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 );
} );
} );