Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
11 changes: 10 additions & 1 deletion packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,16 @@ export const mergeBlocks =
return;
}

if ( isUnmodifiedDefaultBlock( blockA ) ) {
// An unmodified default block adds nothing to the merge. Neither
// does an empty block of a different type, where merging would
// transform blockB into blockA's type instead (a paragraph deleted
// into an empty heading became a heading), so remove blockA in both
// cases.
if (
isUnmodifiedDefaultBlock( blockA ) ||
( blockA.name !== blockB.name &&
isUnmodifiedBlock( blockA, 'content' ) )
) {
const isASelected = select.isBlockSelected( clientIdA );

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

test( 'should forward delete an empty heading without transforming the next block', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/heading' } );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'My paragraph' );
await page.keyboard.press( 'ArrowUp' );

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

await page.keyboard.press( 'Delete' );
// The caret lands at the start of the surviving paragraph.
await page.keyboard.type( '‸' );

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

test( 'should forward delete an empty heading before an empty paragraph', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/heading' } );
await editor.insertBlock( { name: 'core/paragraph' } );
await editor.canvas
.getByRole( 'document', { name: 'Block: Heading' } )
.click();

await page.keyboard.press( 'Delete' );
// Typing proves the surviving block: the empty heading is removed
// and the caret sits in the empty default paragraph.
await page.keyboard.type( '2' );

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

test( 'should place the caret in the next block on forward delete from an empty paragraph', async ( {
editor,
page,
Expand Down
Loading