diff --git a/blocks/editable/index.js b/blocks/editable/index.js index 07ca484d7c8e6..62db20d4c8a75 100644 --- a/blocks/editable/index.js +++ b/blocks/editable/index.js @@ -13,6 +13,7 @@ import { find, defer, noop, + throttle, } from 'lodash'; import { nodeListToReact } from 'dom-react'; import { Fill } from 'react-slot-fill'; @@ -86,6 +87,8 @@ export default class Editable extends Component { this.onSelectionChange = this.onSelectionChange.bind( this ); this.maybePropagateUndo = this.maybePropagateUndo.bind( this ); this.onBeforePastePreProcess = this.onBeforePastePreProcess.bind( this ); + this.saveEditorContent = this.saveEditorContent.bind( this ); + this.saveEditorContentThrottled = throttle( this.saveEditorContent, 10100, { leading: true } ); this.state = { formats: {}, @@ -209,10 +212,16 @@ export default class Editable extends Component { } onChange() { + this.saveEditorContentThrottled.cancel(); + if ( ! this.editor.isDirty() ) { return; } + this.saveEditorContent(); + } + + saveEditorContent() { this.savedContent = this.getContent(); this.editor.save(); this.props.onChange( this.savedContent ); @@ -366,6 +375,8 @@ export default class Editable extends Component { if ( keyCode === BACKSPACE ) { this.onSelectionChange(); } + + this.saveEditorContentThrottled(); } splitContent( blocks = [] ) { @@ -528,10 +539,13 @@ export default class Editable extends Component { removeFormat( format ) { this.editor.focus(); this.editor.formatter.remove( format ); + this.saveEditorContent(); } + applyFormat( format, args, node ) { this.editor.focus(); this.editor.formatter.apply( format, args, node ); + this.saveEditorContent(); } changeFormats( formats ) { @@ -595,7 +609,7 @@ export default class Editable extends Component { ); return ( -