Skip to content

Commit

Permalink
WIP: try editable onChange on input
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and youknowriad committed Feb 8, 2018
1 parent 13b181b commit 84132f8
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions blocks/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export default class RichText extends Component {
editor.on( 'BeforeExecCommand', this.maybePropagateUndo );
editor.on( 'PastePreProcess', this.onPastePreProcess, true /* Add before core handlers */ );
editor.on( 'paste', this.onPaste, true /* Add before core handlers */ );
editor.on( 'input', this.onChange );

patterns.apply( this, [ editor ] );

Expand Down Expand Up @@ -358,21 +359,12 @@ export default class RichText extends Component {
}
}

fireChange() {
this.savedContent = this.getContent();
this.editor.save();
this.props.onChange( this.state.empty ? [] : this.savedContent );
}

/**
* Handles any case where the content of the tinyMCE instance has changed.
*/
onChange() {
// Note that due to efficiency, speed and low cost requirements isDirty may
// not reflect reality for a brief period immediately after a change.
if ( this.editor.isDirty() ) {
this.fireChange();
}
this.savedContent = this.state.empty ? [] : this.getContent();
this.props.onChange( this.savedContent );
}

/**
Expand Down Expand Up @@ -500,8 +492,6 @@ export default class RichText extends Component {
return;
}

this.fireChange();

const forward = event.keyCode === DELETE;

if ( this.props.onMerge ) {
Expand Down Expand Up @@ -680,19 +670,10 @@ export default class RichText extends Component {
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
this.editor.save();
}

setContent( content ) {
if ( ! content ) {
content = '';
}

content = renderToString( content );
this.editor.setContent( content );
setContent( content = '' ) {
this.editor.setContent( renderToString( content ) );
}

getContent() {
Expand Down

0 comments on commit 84132f8

Please sign in to comment.