From 478fb976ee4e3077f617893669cb0460918d3ef5 Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Tue, 15 Oct 2024 10:37:01 -0700 Subject: [PATCH 1/2] Fix focus inserted default block --- .../edit-post/src/components/layout/use-padding-appender.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edit-post/src/components/layout/use-padding-appender.js b/packages/edit-post/src/components/layout/use-padding-appender.js index edffc6f3dd07c9..f89873144dafa5 100644 --- a/packages/edit-post/src/components/layout/use-padding-appender.js +++ b/packages/edit-post/src/components/layout/use-padding-appender.js @@ -31,7 +31,7 @@ export function usePaddingAppender( enabled ) { return; } - event.stopPropagation(); + event.preventDefault(); const blockOrder = registry .select( blockEditorStore ) From 391c45f02130d07164aeb094ee5c1e53852dd2ea Mon Sep 17 00:00:00 2001 From: Mitchell Austin Date: Tue, 15 Oct 2024 12:12:07 -0700 Subject: [PATCH 2/2] Support clicks below the padding in the iframed editor --- .../src/components/layout/use-padding-appender.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/edit-post/src/components/layout/use-padding-appender.js b/packages/edit-post/src/components/layout/use-padding-appender.js index f89873144dafa5..ee1484f518d7a0 100644 --- a/packages/edit-post/src/components/layout/use-padding-appender.js +++ b/packages/edit-post/src/components/layout/use-padding-appender.js @@ -16,7 +16,13 @@ export function usePaddingAppender( enabled ) { const effect = useRefEffect( ( node ) => { function onMouseDown( event ) { - if ( event.target !== node ) { + if ( + event.target !== node && + // Tests for the parent element because in the iframed editor if the click is + // below the padding the target will be the parent element (html) and should + // still be treated as intent to append. + event.target !== node.parentElement + ) { return; } @@ -50,9 +56,12 @@ export function usePaddingAppender( enabled ) { insertDefaultBlock(); } } - node.addEventListener( 'mousedown', onMouseDown ); + const { ownerDocument } = node; + // Adds the listener on the document so that in the iframed editor clicks below the + // padding can be handled as they too should be treated as intent to append. + ownerDocument.addEventListener( 'mousedown', onMouseDown ); return () => { - node.removeEventListener( 'mousedown', onMouseDown ); + ownerDocument.removeEventListener( 'mousedown', onMouseDown ); }; }, [ registry ]