From b6a2fa2664a5b15a64ad33b9035dc54466539f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Fri, 22 Jul 2022 11:18:49 +0200 Subject: [PATCH] Address feedback --- packages/block-editor/src/store/actions.js | 30 +++++++++---------- .../blocks/__snapshots__/quote.test.js.snap | 6 ---- .../specs/editor/blocks/quote.test.js | 6 +++- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index 5cc07e8e749a5a..82ee5b79887136 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1159,28 +1159,28 @@ export const removeBlocks = return; } - if ( selectPrevious ) { - dispatch.selectPreviousBlock( clientIds[ 0 ] ); - } - - dispatch( { type: 'REMOVE_BLOCKS', clientIds } ); - const blockOrder = select.getBlockOrder( rootClientId ); const { __unstableRemoveEmpty } = select.getBlockListSettings( rootClientId ) || {}; + const removeEmpty = + blockOrder.length === clientIds.length && __unstableRemoveEmpty; - if ( blockOrder.length === 0 && __unstableRemoveEmpty ) { - if ( selectPrevious ) { - dispatch.selectPreviousBlock( rootClientId ); - } + if ( selectPrevious ) { + dispatch.selectPreviousBlock( + removeEmpty ? rootClientId : clientIds[ 0 ] + ); + } + + dispatch( { type: 'REMOVE_BLOCKS', clientIds } ); + if ( removeEmpty ) { dispatch( { type: 'REMOVE_BLOCKS', clientIds: [ rootClientId ] } ); - } else { - // To avoid a focus loss when removing the last block, assure there - // is always a default block if the last of the blocks have been - // removed. - dispatch( ensureDefaultBlock() ); } + + // To avoid a focus loss when removing the last block, assure there + // is always a default block if the last of the blocks have been + // removed. + dispatch( ensureDefaultBlock() ); }; /** diff --git a/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap b/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap index ef4346c203ecfb..d1121eebc29bda 100644 --- a/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap +++ b/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap @@ -98,12 +98,6 @@ exports[`Quote can be created by using > at the start of a paragraph block 1`] = " `; -exports[`Quote can be removed 1`] = ` -" -

ab

-" -`; - exports[`Quote can be split at the end 1`] = ` "
diff --git a/packages/e2e-tests/specs/editor/blocks/quote.test.js b/packages/e2e-tests/specs/editor/blocks/quote.test.js index 97a5c1bc607de1..aac4d4d3426de8 100644 --- a/packages/e2e-tests/specs/editor/blocks/quote.test.js +++ b/packages/e2e-tests/specs/editor/blocks/quote.test.js @@ -156,6 +156,10 @@ describe( 'Quote', () => { await page.keyboard.type( 'b' ); // Expect "ab" in the paragraph. - expect( await getEditedPostContent() ).toMatchSnapshot(); + expect( await getEditedPostContent() ).toMatchInlineSnapshot( ` + " +

ab

+ " + ` ); } ); } );