Skip to content

Commit

Permalink
Fix selection after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 11, 2021
1 parent 9f44e33 commit 6fe29bd
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,10 @@ export function* mergeBlocks( firstBlockClientId, secondBlockClientId ) {
blocksWithTheSameType[ 0 ].attributes
);

let newAttributeKey, newOffset;

if ( canRestoreTextSelection ) {
const newAttributeKey = findKey(
newAttributeKey = findKey(
updatedAttributes,
( v ) =>
typeof v === 'string' &&
Expand All @@ -821,7 +823,7 @@ export function* mergeBlocks( firstBlockClientId, secondBlockClientId ) {
multilineWrapperTags,
preserveWhiteSpace,
} );
const newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
newOffset = convertedValue.text.indexOf( START_OF_SELECTED_AREA );
const newValue = remove( convertedValue, newOffset, newOffset + 1 );
const newHtml = toHTMLString( {
value: newValue,
Expand All @@ -830,13 +832,6 @@ export function* mergeBlocks( firstBlockClientId, secondBlockClientId ) {
} );

updatedAttributes[ newAttributeKey ] = newHtml;

yield selectionChange(
blockA.clientId,
newAttributeKey,
newOffset,
newOffset
);
}

yield* replaceBlocks(
Expand All @@ -852,6 +847,15 @@ export function* mergeBlocks( firstBlockClientId, secondBlockClientId ) {
...blocksWithTheSameType.slice( 1 ),
]
);

if ( canRestoreTextSelection ) {
yield selectionChange(
blockA.clientId,
newAttributeKey,
newOffset,
newOffset
);
}
}

/**
Expand Down

0 comments on commit 6fe29bd

Please sign in to comment.