Skip to content
Prev Previous commit
Next Next commit
Fix TinyMCE isCollapsed error when merging two blocks
  • Loading branch information
youknowriad committed Apr 27, 2017
commit 15b70c1cf2c315f4e9db44beda2b9743c078587d
5 changes: 3 additions & 2 deletions blocks/components/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ export default class Editable extends wp.element.Component {

onKeyDown( event ) {
if ( this.props.onMerge && event.keyCode === KEYCODE_BACKSPACE && this.isStartOfEditor() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it was intentional, but nice optimization having the heaviest part of the condition performed last and taking advantage of short-circuiting 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional :)

event.preventDefault();
this.onChange();
this.props.onMerge( this.editor.getContent() );

// Debouncing this call avoids TinyMCE error while handling `keydown` event
setTimeout( () => this.props.onMerge( this.editor.getContent() ) );
}
}

Expand Down