From 64bb52e844205b8ff3b700ddc125626932f164d2 Mon Sep 17 00:00:00 2001 From: iseulde Date: Mon, 5 Jun 2017 20:00:05 +0200 Subject: [PATCH] Add cut event handler --- editor/modes/visual-editor/block-list.js | 21 ++++++++++++++++++++- editor/modes/visual-editor/block.js | 2 -- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/editor/modes/visual-editor/block-list.js b/editor/modes/visual-editor/block-list.js index 92ab53c98df0c..06cdaac8d69b5 100644 --- a/editor/modes/visual-editor/block-list.js +++ b/editor/modes/visual-editor/block-list.js @@ -18,6 +18,7 @@ import { getMultiSelectedBlocksStartUid, getMultiSelectedBlocksEndUid, getMultiSelectedBlocks, + getMultiSelectedBlockUids, } from '../../selectors'; const INSERTION_POINT_PLACEHOLDER = '[[insertion-point]]'; @@ -30,6 +31,7 @@ class VisualEditorBlockList extends wp.element.Component { this.onSelectionChange = this.onSelectionChange.bind( this ); this.onSelectionEnd = this.onSelectionEnd.bind( this ); this.onCopy = this.onCopy.bind( this ); + this.onCut = this.onCut.bind( this ); this.state = { selectionAtStart: null, @@ -38,10 +40,12 @@ class VisualEditorBlockList extends wp.element.Component { componentDidMount() { document.addEventListener( 'copy', this.onCopy ); + document.addEventListener( 'cut', this.onCut ); } componentWillUnmount() { document.removeEventListener( 'copy', this.onCopy ); + document.removeEventListener( 'cut', this.onCut ); } onCopy( event ) { @@ -56,6 +60,16 @@ class VisualEditorBlockList extends wp.element.Component { } } + onCut( event ) { + const { multiSelectedBlockUids } = this.props; + + this.onCopy( event ); + + if ( multiSelectedBlockUids.length ) { + this.props.onRemove( multiSelectedBlockUids ); + } + } + onSelectionStart( uid ) { this.setState( { selectionAtStart: uid } ); } @@ -83,7 +97,7 @@ class VisualEditorBlockList extends wp.element.Component { } render() { - const { blocks, insertionPoint } = this.props; + const { blocks, insertionPoint, multiSelectedBlockUids } = this.props; const insertionPointIndex = blocks.indexOf( insertionPoint ); const blocksWithInsertionPoint = insertionPoint ? [ @@ -112,6 +126,7 @@ class VisualEditorBlockList extends wp.element.Component { onSelectionStart={ () => this.onSelectionStart( uid ) } onSelectionChange={ () => this.onSelectionChange( uid ) } onSelectionEnd={ this.onSelectionEnd } + multiSelectedBlockUids={ multiSelectedBlockUids } /> ); } ) } @@ -127,10 +142,14 @@ export default connect( selectionStart: getMultiSelectedBlocksStartUid( state ), selectionEnd: getMultiSelectedBlocksEndUid( state ), multiSelectedBlocks: getMultiSelectedBlocks( state ), + multiSelectedBlockUids: getMultiSelectedBlockUids( state ), } ), ( dispatch ) => ( { onMultiSelect( { start, end } ) { dispatch( { type: 'MULTI_SELECT', start, end } ); }, + onRemove( uids ) { + dispatch( { type: 'REMOVE_BLOCKS', uids } ); + }, } ) )( VisualEditorBlockList ); diff --git a/editor/modes/visual-editor/block.js b/editor/modes/visual-editor/block.js index d4ae33463a25b..86c2c3737fa0f 100644 --- a/editor/modes/visual-editor/block.js +++ b/editor/modes/visual-editor/block.js @@ -35,7 +35,6 @@ import { isBlockSelected, isBlockMultiSelected, isFirstMultiSelectedBlock, - getMultiSelectedBlockUids, isTypingInBlock, } from '../../selectors'; @@ -307,7 +306,6 @@ export default connect( isSelected: isBlockSelected( state, ownProps.uid ), isMultiSelected: isBlockMultiSelected( state, ownProps.uid ), isFirstMultiSelected: isFirstMultiSelectedBlock( state, ownProps.uid ), - multiSelectedBlockUids: getMultiSelectedBlockUids( state ), isHovered: isBlockHovered( state, ownProps.uid ), focus: getBlockFocus( state, ownProps.uid ), isTyping: isTypingInBlock( state, ownProps.uid ),