File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -1062,15 +1062,16 @@ export const __unstableSplitSelection =
1062
1062
const clonedBlocks = [ ...blocks ] ;
1063
1063
const firstBlock = clonedBlocks . shift ( ) ;
1064
1064
const headType = getBlockType ( head . name ) ;
1065
+ const firstBlocks =
1066
+ headType . merge && switchToBlockType ( firstBlock , headType . name ) ;
1065
1067
1066
- if ( head . name === firstBlock . name && headType . merge ) {
1068
+ if ( firstBlocks ?. length ) {
1069
+ const first = firstBlocks . shift ( ) ;
1067
1070
output . push ( {
1068
1071
...head ,
1069
- attributes : headType . merge (
1070
- head . attributes ,
1071
- firstBlock . attributes
1072
- ) ,
1072
+ attributes : headType . merge ( head . attributes , first . attributes ) ,
1073
1073
} ) ;
1074
+ clonedBlocks . unshift ( ...firstBlocks ) ;
1074
1075
} else {
1075
1076
if ( ! isUnmodifiedBlock ( head ) ) {
1076
1077
output . push ( head ) ;
@@ -1086,14 +1087,19 @@ export const __unstableSplitSelection =
1086
1087
}
1087
1088
1088
1089
if ( lastBlock ) {
1089
- if ( lastBlock . name === tail . name && tailType . merge ) {
1090
+ const lastBlocks =
1091
+ tailType . merge && switchToBlockType ( lastBlock , tailType . name ) ;
1092
+
1093
+ if ( lastBlocks ?. length ) {
1094
+ const last = lastBlocks . pop ( ) ;
1090
1095
output . push ( {
1091
1096
...tail ,
1092
1097
attributes : tailType . merge (
1093
- lastBlock . attributes ,
1098
+ last . attributes ,
1094
1099
tail . attributes
1095
1100
) ,
1096
1101
} ) ;
1102
+ output . push ( ...lastBlocks ) ;
1097
1103
offset = create ( {
1098
1104
html : lastBlock . attributes [ selectionB . attributeKey ] ,
1099
1105
} ) . text . length ;
Original file line number Diff line number Diff line change @@ -457,6 +457,12 @@ function maybeCheckTransformIsMatch( transform, blocks ) {
457
457
*/
458
458
export function switchToBlockType ( blocks , name ) {
459
459
const blocksArray = Array . isArray ( blocks ) ? blocks : [ blocks ] ;
460
+
461
+ // Return early if all blocks are already of the correct block type.
462
+ if ( blocksArray . every ( ( block ) => block . name === name ) ) {
463
+ return blocksArray ;
464
+ }
465
+
460
466
const isMultiBlock = blocksArray . length > 1 ;
461
467
const firstBlock = blocksArray [ 0 ] ;
462
468
const sourceName = firstBlock . name ;
You can’t perform that action at this time.
0 commit comments