From 473563af5185c741c68e962b36994db66f8970a3 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 1 May 2017 11:08:31 +0100 Subject: [PATCH] Editable: Avoid unnecessary updateContent calls --- blocks/components/editable/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/blocks/components/editable/index.js b/blocks/components/editable/index.js index 58a336a1f2d9e2..52022c05ae6f6e 100644 --- a/blocks/components/editable/index.js +++ b/blocks/components/editable/index.js @@ -108,8 +108,9 @@ export default class Editable extends wp.element.Component { return; } + this.savedContent = this.getContent(); this.editor.save(); - this.props.onChange( this.getContent() ); + this.props.onChange( this.savedContent ); } isStartOfEditor() { @@ -216,7 +217,8 @@ export default class Editable extends wp.element.Component { updateContent() { const bookmark = this.editor.selection.getBookmark( 2, true ); - this.setContent( this.props.value ); + this.savedContent = this.props.value; + this.setContent( this.savedContent ); this.editor.selection.moveToBookmark( bookmark ); // Saving the editor on updates avoid unecessary onChanges calls // These calls can make the focus jump @@ -266,10 +268,13 @@ export default class Editable extends wp.element.Component { this.focus(); } + // The savedContent var allows us to avoid updating the content right after an onChange call if ( this.props.tagName === prevProps.tagName && this.props.value !== prevProps.value && - ! isEqual( this.props.value, prevProps.value ) + this.props.value !== this.savedContent && + ! isEqual( this.props.value, prevProps.value ) && + ! isEqual( this.props.value, this.savedContent ) ) { this.updateContent(); }