Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: After saving, ability to save isn't available until you exit a block #2418

Closed
wants to merge 8 commits into from
16 changes: 15 additions & 1 deletion blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
find,
defer,
noop,
throttle,
} from 'lodash';
import { nodeListToReact } from 'dom-react';
import { Fill } from 'react-slot-fill';
Expand Down Expand Up @@ -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: {},
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -366,6 +375,8 @@ export default class Editable extends Component {
if ( keyCode === BACKSPACE ) {
this.onSelectionChange();
}

this.saveEditorContentThrottled();
}

splitContent( blocks = [] ) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -595,7 +609,7 @@ export default class Editable extends Component {
);

return (
<div className={ classes }>
<div className={ classes } >
{ focus &&
<Fill name="Formatting.Toolbar">
{ ! inlineToolbar && formatToolbar }
Expand Down