Skip to content

Commit

Permalink
Backspace does not trigger selectionChange event in Chrome (#883)
Browse files Browse the repository at this point in the history
Trigger the callback on keyup as well.
This is a bug in Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=725890
  • Loading branch information
ellatrix authored May 24, 2017
1 parent f1d1296 commit dc453b3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default class Editable extends wp.element.Component {
this.onFocus = this.onFocus.bind( this );
this.onNodeChange = this.onNodeChange.bind( this );
this.onKeyDown = this.onKeyDown.bind( this );
this.onKeyUp = this.onKeyUp.bind( this );
this.changeFormats = this.changeFormats.bind( this );
this.onSelectionChange = this.onSelectionChange.bind( this );

Expand All @@ -100,6 +101,7 @@ export default class Editable extends wp.element.Component {
editor.on( 'focusin', this.onFocus );
editor.on( 'nodechange', this.onNodeChange );
editor.on( 'keydown', this.onKeyDown );
editor.on( 'keyup', this.onKeyUp );
editor.on( 'selectionChange', this.onSelectionChange );

if ( this.props.onSetup ) {
Expand Down Expand Up @@ -231,6 +233,12 @@ export default class Editable extends wp.element.Component {
}
}

onKeyUp( { keyCode } ) {
if ( keyCode === KEYCODE_BACKSPACE ) {
this.onSelectionChange();
}
}

onNewBlock() {
if ( this.props.tagName || ! this.props.onSplit ) {
return;
Expand Down

0 comments on commit dc453b3

Please sign in to comment.