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
18 changes: 17 additions & 1 deletion packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,23 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
return;
}

if ( getBlockOrder( nextBlockClientId ).length ) {
// Forward deleting an unmodified default block should
// remove it and move into the next block, not pull the
// next block's first item out of it.
if ( isUnmodifiedDefaultBlock( getBlock( clientId ) ) ) {
// Select the first leaf block, so the caret starts at
// the beginning of the block's content rather than on
// a container's shell.
let firstLeafClientId = nextBlockClientId;
while ( getBlockOrder( firstLeafClientId ).length ) {
firstLeafClientId =
getBlockOrder( firstLeafClientId )[ 0 ];
}
registry.batch( () => {
removeBlock( clientId );
selectBlock( firstLeafClientId );
} );
} else if ( getBlockOrder( nextBlockClientId ).length ) {
moveFirstItemUp( nextBlockClientId, false );
} else {
mergeBlocks( clientId, nextBlockClientId );
Expand Down
56 changes: 56 additions & 0 deletions test/e2e/specs/editor/various/splitting-merging.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,62 @@ test.describe( 'splitting and merging blocks (@firefox, @webkit)', () => {
] );
} );

test( 'should forward delete an empty paragraph without breaking apart the next block', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/paragraph' } );
await editor.insertBlock( {
name: 'core/list',
innerBlocks: [
{ name: 'core/list-item', attributes: { content: 'one' } },
{ name: 'core/list-item', attributes: { content: 'two' } },
],
} );

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

await expect.poll( editor.getBlocks ).toMatchObject( [
{ name: 'core/paragraph', attributes: { content: '' } },
{
name: 'core/list',
innerBlocks: [
{
name: 'core/list-item',
attributes: { content: 'one' },
},
{
name: 'core/list-item',
attributes: { content: 'two' },
},
],
},
] );

await page.keyboard.press( 'Delete' );
await page.keyboard.type( '|' );

// The empty paragraph is removed and the list is left intact, with
// the caret at the start of its first item.
await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/list',
innerBlocks: [
{
name: 'core/list-item',
attributes: { content: '|one' },
},
{
name: 'core/list-item',
attributes: { content: 'two' },
},
],
},
] );
} );

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