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

Fix dragging in inspector causing block deselection #40604

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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export default function useSelectionObserver() {
const endClientId = getBlockClientId(
extractSelectionEndNode( selection )
);

// If the selection did not involve a block, return early.
if ( clientId === undefined && endClientId === undefined ) {
setContentEditableWrapper( node, false );
return;
}

const isSingularSelection = clientId === endClientId;

if ( isSingularSelection ) {
Expand Down
32 changes: 31 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 @@ -9,6 +9,7 @@ import {
pressKeyWithModifier,
insertBlock,
clickBlockToolbarButton,
openDocumentSettingsSidebar,
} from '@wordpress/e2e-test-utils';

const getActiveBlockName = async () =>
Expand Down Expand Up @@ -701,7 +702,7 @@ describe( 'Writing Flow', () => {
).toBe( 'Table' );
} );

it( 'Should unselect all blocks when hitting double escape', async () => {
it( 'should unselect all blocks when hitting double escape', async () => {
// Add demo content.
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Random Paragraph' );
Expand All @@ -720,4 +721,33 @@ describe( 'Writing Flow', () => {
activeBlockName = await getActiveBlockName();
expect( activeBlockName ).toBe( undefined );
} );

// Checks for regressions of https://github.com/WordPress/gutenberg/issues/40091.
it( 'does not deselect the block when selecting text outside the editor canvas', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Random Paragraph' );
await openDocumentSettingsSidebar();
const blockDescription = await page.waitForSelector(
'.block-editor-block-card__description'
);
const boundingBox = await blockDescription.boundingBox();
const startPosition = {
x: boundingBox.x + 10,
y: boundingBox.y + 8,
};
const endPosition = {
x: startPosition.x + 50,
y: startPosition.y,
};

await page.mouse.move( startPosition.x, startPosition.y );
await page.mouse.down();
await page.mouse.move( endPosition.x, endPosition.y );
await page.mouse.up();

const selectedParagraph = await page.waitForSelector(
'.wp-block-paragraph.is-selected'
);
expect( selectedParagraph ).toBeDefined();
} );
} );