From e783575fc6fc9ad1eb2e59d959bf35ae808214e1 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Fri, 21 Apr 2017 11:32:04 +0100 Subject: [PATCH] Focus: Fix focus jumps when splitting a text block --- blocks/components/editable/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blocks/components/editable/index.js b/blocks/components/editable/index.js index 0edfba8f520053..97043a30bf6da7 100644 --- a/blocks/components/editable/index.js +++ b/blocks/components/editable/index.js @@ -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 ) { @@ -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() {