From f0280d747e0f4185e9effc8ef9ba5473ed78c028 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 6 Oct 2023 17:37:59 +0300 Subject: [PATCH 1/7] Writing flow: preserve block when merging into empty paragraph --- packages/block-editor/src/store/actions.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index ae4b64a645d3e..72cfaeabd66c7 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -13,6 +13,7 @@ import { switchToBlockType, synchronizeBlocksWithTemplate, getBlockSupport, + isUnmodifiedDefaultBlock, } from '@wordpress/blocks'; import { speak } from '@wordpress/a11y'; import { __, _n, sprintf } from '@wordpress/i18n'; @@ -1009,6 +1010,12 @@ export const mergeBlocks = const [ clientIdA, clientIdB ] = blocks; const blockA = select.getBlock( clientIdA ); + + if ( isUnmodifiedDefaultBlock( blockA ) ) { + dispatch.removeBlock( clientIdA, false ); + return; + } + const blockAType = getBlockType( blockA.name ); if ( ! blockAType ) return; From fb3a45923cca02ed0934b383984fe9460933ed4b Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 6 Oct 2023 18:51:00 +0300 Subject: [PATCH 2/7] Fix double delete --- packages/block-editor/src/components/rich-text/use-delete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/use-delete.js b/packages/block-editor/src/components/rich-text/use-delete.js index f09a15265bd2b..fbf025a5d4ea4 100644 --- a/packages/block-editor/src/components/rich-text/use-delete.js +++ b/packages/block-editor/src/components/rich-text/use-delete.js @@ -43,7 +43,7 @@ export function useDelete( props ) { // an intentional user interaction distinguishing between Backspace and // Delete to remove the empty field, but also to avoid merge & remove // causing destruction of two fields (merge, then removed merged). - if ( onRemove && isEmpty( value ) && isReverse ) { + else if ( onRemove && isEmpty( value ) && isReverse ) { onRemove( ! isReverse ); } From f4d0b7d22607ff4558e6b4ab3eb88cae0ba7b569 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 6 Oct 2023 19:23:40 +0300 Subject: [PATCH 3/7] Add remove fallback for merge --- packages/block-editor/src/components/block-list/block.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/block-editor/src/components/block-list/block.js b/packages/block-editor/src/components/block-list/block.js index 4bf9bb634dbf6..a95075c6f9b42 100644 --- a/packages/block-editor/src/components/block-list/block.js +++ b/packages/block-editor/src/components/block-list/block.js @@ -494,6 +494,8 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => { } moveFirstItemUp( rootClientId ); + } else { + removeBlock( clientId ); } } }, From 3264a5910f2100549978cab05cc0521f284d76a3 Mon Sep 17 00:00:00 2001 From: Ella Date: Fri, 6 Oct 2023 20:58:51 +0300 Subject: [PATCH 4/7] Fix deleting paragraph after block --- packages/block-editor/src/store/actions.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index 72cfaeabd66c7..fa4d651fe79b2 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1012,7 +1012,20 @@ export const mergeBlocks = const blockA = select.getBlock( clientIdA ); if ( isUnmodifiedDefaultBlock( blockA ) ) { - dispatch.removeBlock( clientIdA, false ); + dispatch.removeBlock( + clientIdA, + select.isBlockSelected( clientIdA ) + ); + return; + } + + const blockB = select.getBlock( clientIdB ); + + if ( isUnmodifiedDefaultBlock( blockB ) ) { + dispatch.removeBlock( + clientIdB, + select.isBlockSelected( clientIdB ) + ); return; } @@ -1028,8 +1041,6 @@ export const mergeBlocks = return; } - const blockB = select.getBlock( clientIdB ); - if ( ! blockAType.merge ) { // If there's no merge function defined, attempt merging inner // blocks. From 3c8e1f7b2a513a0d603ceabf8369eae3d2148b1f Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 9 Oct 2023 12:25:36 +0300 Subject: [PATCH 5/7] Fix order --- packages/block-editor/src/store/actions.js | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index fa4d651fe79b2..aa044e8d37d14 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1010,25 +1010,6 @@ export const mergeBlocks = const [ clientIdA, clientIdB ] = blocks; const blockA = select.getBlock( clientIdA ); - - if ( isUnmodifiedDefaultBlock( blockA ) ) { - dispatch.removeBlock( - clientIdA, - select.isBlockSelected( clientIdA ) - ); - return; - } - - const blockB = select.getBlock( clientIdB ); - - if ( isUnmodifiedDefaultBlock( blockB ) ) { - dispatch.removeBlock( - clientIdB, - select.isBlockSelected( clientIdB ) - ); - return; - } - const blockAType = getBlockType( blockA.name ); if ( ! blockAType ) return; @@ -1041,6 +1022,8 @@ export const mergeBlocks = return; } + const blockB = select.getBlock( clientIdB ); + if ( ! blockAType.merge ) { // If there's no merge function defined, attempt merging inner // blocks. @@ -1108,6 +1091,22 @@ export const mergeBlocks = return; } + if ( isUnmodifiedDefaultBlock( blockA ) ) { + dispatch.removeBlock( + clientIdA, + select.isBlockSelected( clientIdA ) + ); + return; + } + + if ( isUnmodifiedDefaultBlock( blockB ) ) { + dispatch.removeBlock( + clientIdB, + select.isBlockSelected( clientIdB ) + ); + return; + } + const blockBType = getBlockType( blockB.name ); const { clientId, attributeKey, offset } = select.getSelectionStart(); const selectedBlockType = From 12c441f2eca48e68b8478d020872a3f048be3f81 Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 9 Oct 2023 13:16:20 +0300 Subject: [PATCH 6/7] Fix deleting paragraph after non mergeable block --- packages/block-editor/src/store/actions.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index aa044e8d37d14..0acea689033bc 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1014,17 +1014,12 @@ export const mergeBlocks = if ( ! blockAType ) return; + const blockB = select.getBlock( clientIdB ); + if ( ! blockAType.merge && - ! getBlockSupport( blockA.name, '__experimentalOnMerge' ) + getBlockSupport( blockA.name, '__experimentalOnMerge' ) ) { - dispatch.selectBlock( blockA.clientId ); - return; - } - - const blockB = select.getBlock( clientIdB ); - - if ( ! blockAType.merge ) { // If there's no merge function defined, attempt merging inner // blocks. const blocksWithTheSameType = switchToBlockType( From 1171b187b3350ab690dfeea4ffd317160937c1c9 Mon Sep 17 00:00:00 2001 From: Ella Date: Mon, 9 Oct 2023 14:04:29 +0300 Subject: [PATCH 7/7] Handle ! blockAType.merge --- packages/block-editor/src/store/actions.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index 0acea689033bc..2975a41dbb9d9 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1102,6 +1102,11 @@ export const mergeBlocks = return; } + if ( ! blockAType.merge ) { + dispatch.selectBlock( blockA.clientId ); + return; + } + const blockBType = getBlockType( blockB.name ); const { clientId, attributeKey, offset } = select.getSelectionStart(); const selectedBlockType =