From b6374b75f3231cea6722e6f8307abdf98ceeca52 Mon Sep 17 00:00:00 2001 From: Ella Date: Thu, 23 May 2024 14:11:02 +0200 Subject: [PATCH 1/2] Writing flow: fix heading crash on split --- packages/block-editor/src/store/actions.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index c9a1430a078fa5..74814cf22746bc 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1000,7 +1000,10 @@ export const __unstableSplitSelection = const first = firstBlocks.shift(); head = { ...head, - attributes: headType.merge( head.attributes, first.attributes ), + attributes: { + ...head.attributes, + ...headType.merge( head.attributes, first.attributes ), + }, }; output.push( head ); selection = { @@ -1034,10 +1037,10 @@ export const __unstableSplitSelection = const last = lastBlocks.pop(); output.push( { ...tail, - attributes: tailType.merge( - last.attributes, - tail.attributes - ), + attributes: { + ...tail.attributes, + ...tailType.merge( last.attributes, tail.attributes ), + }, } ); output.push( ...lastBlocks ); selection = { From 980d85bf1d254ad8012610557e9828330595bcc5 Mon Sep 17 00:00:00 2001 From: Ella Date: Thu, 23 May 2024 14:25:40 +0200 Subject: [PATCH 2/2] Add e2e test --- .../editor/various/copy-cut-paste.spec.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/e2e/specs/editor/various/copy-cut-paste.spec.js b/test/e2e/specs/editor/various/copy-cut-paste.spec.js index 539791d39e45f0..48392170e66dde 100644 --- a/test/e2e/specs/editor/various/copy-cut-paste.spec.js +++ b/test/e2e/specs/editor/various/copy-cut-paste.spec.js @@ -640,4 +640,41 @@ test.describe( 'Copy/cut/paste', () => { }, ] ); } ); + + // See https://github.com/WordPress/gutenberg/pull/61900 + test( 'should inherit heading attributes on paste split', async ( { + pageUtils, + editor, + page, + } ) => { + await editor.insertBlock( { + name: 'core/heading', + attributes: { + content: 'AB', + }, + } ); + await page.keyboard.press( 'ArrowRight' ); + + pageUtils.setClipboardData( { + html: '

a

b

', + } ); + await pageUtils.pressKeys( 'primary+v' ); + + expect( await editor.getBlocks() ).toMatchObject( [ + { + name: 'core/heading', + attributes: { + content: 'Aa', + level: 2, + }, + }, + { + name: 'core/heading', + attributes: { + content: 'bB', + level: 2, + }, + }, + ] ); + } ); } );