From c4cfb73eab416dee94cffe3b4f16fd7315aefed3 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 4 May 2017 15:53:11 -0400 Subject: [PATCH] Remove focused block on backspace --- editor/modes/visual-editor/block.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index d3cc4f52b04051..0c90fe510e4f1e 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -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; } @@ -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; @@ -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 }