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
14 changes: 10 additions & 4 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,10 +1253,16 @@ export const mergeBlocks =
}

if ( isUnmodifiedDefaultBlock( blockA ) ) {
dispatch.removeBlock(
clientIdA,
select.isBlockSelected( clientIdA )
);
const isASelected = select.isBlockSelected( clientIdA );

if ( isASelected ) {
registry.batch( () => {
dispatch.removeBlock( clientIdA, false );
dispatch.selectBlock( clientIdB, 0 );
} );
} else {
dispatch.removeBlock( clientIdA, false );
}
return;
}

Expand Down
35 changes: 35 additions & 0 deletions test/e2e/specs/editor/various/splitting-merging.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,41 @@ test.describe( 'splitting and merging blocks (@firefox, @webkit)', () => {
);
} );

test( 'should place the caret in the next block on forward delete from an empty paragraph', async ( {
editor,
page,
} ) => {
for ( const content of [ 'first', '', '', 'last' ] ) {
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content },
} );
}

await editor.canvas
.getByRole( 'document', { name: 'Empty block' } )
.first()
.click();

// Forward delete removes the empty block; the caret must move to
// the start of the next block, not the end of the previous one,
// so repeated presses keep deleting forward.
await page.keyboard.press( 'Delete' );
await page.keyboard.press( 'Delete' );
await page.keyboard.type( '|' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/paragraph',
attributes: { content: 'first' },
},
{
name: 'core/paragraph',
attributes: { content: '|last' },
},
] );
} );

test( 'should remove empty paragraph block on backspace', async ( {
editor,
page,
Expand Down
Loading