diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js index 2033ce14cb8f7d..688a5287052b68 100644 --- a/packages/editor/src/components/rich-text/index.js +++ b/packages/editor/src/components/rich-text/index.js @@ -682,18 +682,6 @@ export class RichText extends Component { this.savedContent = value; } - // If blocks are merged, but the content remains the same, e.g. merging - // an empty paragraph into another, then also set the selection to the - // end. - if ( isSelected && ! prevProps.isSelected && ! this.isActive() ) { - const record = this.formatToValue( value ); - const prevRecord = this.formatToValue( prevProps.value ); - const length = getTextContent( prevRecord ).length; - record.start = length; - record.end = length; - this.applyRecord( record ); - } - // If any format props update, reapply value. const shouldReapply = Object.keys( this.props ).some( ( name ) => { if ( name.indexOf( 'format_' ) !== 0 ) { diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index e013cc5b7a0ed3..385e99e8be5366 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -795,6 +795,9 @@ export function blockSelection( state = { // If there is replacement block(s), assign first's client ID as // the next selected block. If empty replacement, reset to null. const nextSelectedBlockClientId = get( action.blocks, [ 0, 'clientId' ], null ); + if ( nextSelectedBlockClientId === state.start && nextSelectedBlockClientId === state.end ) { + return state; + } return { ...state, diff --git a/packages/editor/src/store/test/reducer.js b/packages/editor/src/store/test/reducer.js index 2ddb631b5e2139..884314fe553098 100644 --- a/packages/editor/src/store/test/reducer.js +++ b/packages/editor/src/store/test/reducer.js @@ -1761,6 +1761,25 @@ describe( 'state', () => { } ); } ); + it( 'should not replace the selected block if we keep it when replacing blocks', () => { + const original = deepFreeze( { start: 'chicken', end: 'chicken' } ); + const state = blockSelection( original, { + type: 'REPLACE_BLOCKS', + clientIds: [ 'chicken' ], + blocks: [ + { + clientId: 'chicken', + name: 'core/freeform', + }, + { + clientId: 'wings', + name: 'core/freeform', + } ], + } ); + + expect( state ).toBe( original ); + } ); + it( 'should reset if replacing with empty set', () => { const original = deepFreeze( { start: 'chicken', end: 'chicken' } ); const state = blockSelection( original, {