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
7 changes: 5 additions & 2 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {

if (
blockOrder.length === 1 &&
isUnmodifiedBlock( getBlock( firstClientId ) )
isUnmodifiedBlock( getBlock( firstClientId ), 'content' )
) {
removeBlock( _clientId );
} else if ( isTextualWrapper ) {
Expand Down Expand Up @@ -393,7 +393,10 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {

if (
! getBlockOrder( _clientId ).length &&
isUnmodifiedBlock( getBlock( _clientId ) )
isUnmodifiedBlock(
getBlock( _clientId ),
'content'
)
) {
removeBlock( _clientId, false );
}
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/specs/editor/blocks/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,46 @@ test.describe( 'List (@firefox)', () => {
] );
} );

test( 'should remove an anchored list when deleting its last item', async ( {
editor,
page,
} ) => {
await editor.insertBlock( {
name: 'core/list',
attributes: { anchor: 'list' },
innerBlocks: [
{ name: 'core/list-item', attributes: { anchor: 'item' } },
],
} );
// Inserting selects the list container; ArrowDown moves the caret
// into the sole empty item.
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.type( 'x' );

// Typing lands in the sole item, verifying both the setup and the
// caret position.
await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/list',
attributes: { anchor: 'list' },
innerBlocks: [
{
name: 'core/list-item',
attributes: { content: 'x', anchor: 'item' },
},
],
},
] );

// Delete the text, then the emptied item: the anchors are not
// content, so the item and the list are removed together instead
// of the item being lifted out as a paragraph first.
await page.keyboard.press( 'Backspace' );
await page.keyboard.press( 'Backspace' );

await expect.poll( editor.getBlocks ).toEqual( [] );
} );

test( 'should leave nested list intact when deleting the parent item', async ( {
editor,
page,
Expand Down
Loading