From 4cbf35d65be16806e51fe7d7ede701e77013f342 Mon Sep 17 00:00:00 2001 From: ella Date: Tue, 27 Oct 2026 20:54:13 -0700 Subject: [PATCH] Block editor: Show the hover outline on a block while the caret is in text While the caret is in a paragraph, heading or list item, the canvas is one editing host, so every block counts as editable and the hover outline never showed, although the grab cursor does. Count the block's own element as draggable when it is only editable because of the editing host. Co-Authored-By: Claude Opus 5.5 --- .../use-block-props/use-is-hovered.ts | 6 +++- .../editor/various/draggable-blocks.spec.js | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/block-list/use-block-props/use-is-hovered.ts b/packages/block-editor/src/components/block-list/use-block-props/use-is-hovered.ts index d41ef36a305fe5..0a16d708c8471a 100644 --- a/packages/block-editor/src/components/block-list/use-block-props/use-is-hovered.ts +++ b/packages/block-editor/src/components/block-list/use-block-props/use-is-hovered.ts @@ -43,12 +43,16 @@ export function useIsHovered( { // editability check can force a style recalculation, so it // runs once the pointer rests, which also keeps the // outline from flashing on blocks it merely passes over. + // The block's own element is only editable inside an + // editing host, and a press on it still drags the block. // Mouse events target elements. const target = event.target as HTMLElement; timeoutId = setTimeout( () => { node.classList.toggle( 'is-hovered-draggable', - ! target.isContentEditable + ! target.isContentEditable || + ( target === node && + node.contentEditable === 'inherit' ) ); }, 100 ); } diff --git a/test/e2e/specs/editor/various/draggable-blocks.spec.js b/test/e2e/specs/editor/various/draggable-blocks.spec.js index 4a99c3ee2f3e6e..46ab9cc585b6de 100644 --- a/test/e2e/specs/editor/various/draggable-blocks.spec.js +++ b/test/e2e/specs/editor/various/draggable-blocks.spec.js @@ -549,6 +549,39 @@ test.describe( 'Draggable block', () => { ] ); } ); + test( 'shows the hover outline on a block while the caret is in text (@firefox, @webkit)', async ( { + page, + editor, + } ) => { + await editor.insertBlock( { + name: 'core/paragraph', + attributes: { content: 'Text' }, + } ); + await editor.insertBlock( { name: 'core/separator' } ); + + // Move the caret from the selected separator into the paragraph. + await page.keyboard.press( 'ArrowUp' ); + await expect( + editor.canvas.getByRole( 'textbox', { name: 'Editor canvas' } ) + ).toHaveCount( 1 ); + + const separator = editor.canvas.getByRole( 'document', { + name: 'Block: Separator', + } ); + await separator.hover(); + await expect + .poll( () => + separator.evaluate( + ( n ) => + n.ownerDocument.defaultView.getComputedStyle( + n, + '::after' + ).outlineStyle + ) + ) + .toBe( 'solid' ); + } ); + test( 'can drag a multi-selection by dragging inside a selected block', async ( { editor, page,