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 @@ -191,6 +191,26 @@ export default function useSelectionObserver() {
return;
}

// On mouseup, if the native selection is within one block
// but the click target is a different block, bail out
// and let the clicked block's focus handler manage
// selection.
if (
event.type === 'mouseup' &&
! event.shiftKey &&
! isMultiSelecting() &&
startClientId === endClientId
) {
const clickedClientId = getBlockClientId( event.target );
if (
clickedClientId &&
clickedClientId !== startClientId
) {
selection.removeAllRanges();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is setting this selection?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, selection in the previous block remains; this aims to match the behavior of switching selection between RichText blocks. Here's the screencast with this line commented out.

CleanShot.2026-02-12.at.13.58.50.mp4

return;
}
}

const isSingularSelection = startClientId === endClientId;
if ( isSingularSelection ) {
if ( ! isMultiSelecting() ) {
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/specs/editor/various/writing-flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,28 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => {
editor.canvas.locator( '[data-type="core/block"]' )
).toBeFocused();
} );

test( 'should select non-contenteditable block via click after partial selection', async ( {
editor,
pageUtils,
} ) => {
await editor.insertBlock( { name: 'core/paragraph' } );
await editor.insertBlock( { name: 'core/spacer' } );
await editor.canvas
.getByRole( 'document', { name: 'Empty block' } )
.fill( 'A partial selection' );
await pageUtils.pressKeys( 'shiftAlt+ArrowLeft' );

const spacer = editor.canvas.getByRole( 'document', {
name: 'Block: Spacer',
} );
await spacer.click();

await expect( spacer ).toBeFocused();
await expect(
editor.canvas.getByRole( 'document', { name: 'Block: Paragraph' } )
).not.toBeFocused();
} );
} );

class WritingFlowUtils {
Expand Down
Loading