Skip to content

Commit

Permalink
Focus: Fix focus jumps when splitting a text block (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Apr 24, 2017
1 parent d86588a commit 53b8417
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion blocks/components/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export default class Editable extends wp.element.Component {
this.editor.setContent( this.props.value || '' );
const hasAfter = !! childNodes.slice( splitIndex )
.reduce( ( memo, node ) => memo + node.textContent, '' );
this.props.onSplit( before, hasAfter ? after : '' );

// The setTimeout fixes the focus jump to the original block
setTimeout( () => this.props.onSplit( before, hasAfter ? after : '' ) );
}

bindNode( ref ) {
Expand All @@ -117,6 +119,9 @@ export default class Editable extends wp.element.Component {
const bookmark = this.editor.selection.getBookmark( 2, true );
this.editor.setContent( this.props.value );
this.editor.selection.moveToBookmark( bookmark );
// Saving the editor on updates avoid unecessary onChanges calls
// These calls can make the focus jump
this.editor.save();
}

focus() {
Expand Down

0 comments on commit 53b8417

Please sign in to comment.