Skip to content

Commit

Permalink
Merge pull request #666 from WordPress/update/backspace-delete-block
Browse files Browse the repository at this point in the history
Remove focused block on backspace
  • Loading branch information
aduth committed May 5, 2017
2 parents cb0a82c + c4cfb73 commit 2eff0c3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class VisualEditorBlock extends wp.element.Component {
this.maybeDeselect = this.maybeDeselect.bind( this );
this.maybeHover = this.maybeHover.bind( this );
this.maybeStartTyping = this.maybeStartTyping.bind( this );
this.removeOnBackspace = this.removeOnBackspace.bind( this );
this.mergeWithPrevious = this.mergeWithPrevious.bind( this );
this.previousOffset = null;
}
Expand Down Expand Up @@ -76,6 +77,13 @@ class VisualEditorBlock extends wp.element.Component {
}
}

removeOnBackspace( event ) {
const { keyCode, target } = event;
if ( 8 /* Backspace */ === keyCode && target === this.node ) {
this.props.onRemove( this.props.uid );
}
}

mergeWithPrevious() {
const { block, previousBlock, onFocus, replaceBlocks } = this.props;

Expand Down Expand Up @@ -167,6 +175,7 @@ class VisualEditorBlock extends wp.element.Component {
onClick={ onSelect }
onFocus={ onSelect }
onBlur={ this.maybeDeselect }
onKeyDown={ this.removeOnBackspace }
onMouseEnter={ onHover }
onMouseMove={ this.maybeHover }
onMouseLeave={ onMouseLeave }
Expand Down

0 comments on commit 2eff0c3

Please sign in to comment.