Skip to content

Commit

Permalink
[Mobile] Fix caret position after inline paste - after selection refa…
Browse files Browse the repository at this point in the history
…ctor (#15701)

* Rename variables for clarity in inline paste

* Update selection via onSelectionUpdate after inline paste

* Remove unused forceSelectionUpdate function
  • Loading branch information
mkevins authored May 30, 2019
1 parent 13e5851 commit 992a302
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 992a302

Please sign in to comment.