From 992a30221ae4e0e0252ec2d110c54a16fa08fe3e Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Thu, 30 May 2019 17:40:18 +1000 Subject: [PATCH] [Mobile] Fix caret position after inline paste - after selection refactor (#15701) * Rename variables for clarity in inline paste * Update selection via onSelectionUpdate after inline paste * Remove unused forceSelectionUpdate function --- .../src/components/rich-text/index.native.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index 13fcc41771e1c7..5779e6459db14d 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -552,14 +552,14 @@ export class RichText extends Component { if ( typeof pastedContent === 'string' ) { const recordToInsert = create( { html: pastedContent } ); - const insertedContent = insert( currentRecord, recordToInsert ); - const newContent = this.valueToFormat( insertedContent ); + const resultingRecord = insert( currentRecord, recordToInsert ); + const resultingContent = this.valueToFormat( resultingRecord ); this.lastEventCount = undefined; - this.value = newContent; + this.value = resultingContent; // explicitly set selection after inline paste - this.forceSelectionUpdate( insertedContent.start, insertedContent.end ); + this.onSelectionChange( resultingRecord.start, resultingRecord.end ); this.props.onChange( this.value ); } else if ( onSplit ) { @@ -673,15 +673,6 @@ export class RichText extends Component { return value; } - forceSelectionUpdate( start, end ) { - if ( ! this.needsSelectionUpdate ) { - this.needsSelectionUpdate = true; - this.selectionStart = start; - this.selectionEnd = end; - this.forceUpdate(); - } - } - shouldComponentUpdate( nextProps ) { if ( nextProps.tagName !== this.props.tagName ) { this.lastEventCount = undefined;