Skip to content
Closed
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
17 changes: 13 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,19 @@ export const mergeBlocks =
}

if ( isUnmodifiedDefaultBlock( blockA ) ) {
dispatch.removeBlock(
clientIdA,
select.isBlockSelected( clientIdA )
);
// The first block only holds the selection when it is being
// merged forward (forward delete from an empty block). The
// caret must end up at the start of the next block, not at
// the end of the previous one.
const wasSelected = select.isBlockSelected( clientIdA );

registry.batch( () => {
dispatch.removeBlock( clientIdA, false );

if ( wasSelected ) {
dispatch.selectBlock( clientIdB, 0 );
}
} );
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