Skip to content

Commit

Permalink
Add cut event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 10, 2017
1 parent fb189a3 commit 64bb52e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 20 additions & 1 deletion editor/modes/visual-editor/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getMultiSelectedBlocksStartUid,
getMultiSelectedBlocksEndUid,
getMultiSelectedBlocks,
getMultiSelectedBlockUids,
} from '../../selectors';

const INSERTION_POINT_PLACEHOLDER = '[[insertion-point]]';
Expand All @@ -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,
Expand All @@ -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 ) {
Expand All @@ -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 } );
}
Expand Down Expand Up @@ -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
? [
Expand Down Expand Up @@ -112,6 +126,7 @@ class VisualEditorBlockList extends wp.element.Component {
onSelectionStart={ () => this.onSelectionStart( uid ) }
onSelectionChange={ () => this.onSelectionChange( uid ) }
onSelectionEnd={ this.onSelectionEnd }
multiSelectedBlockUids={ multiSelectedBlockUids }
/>
);
} ) }
Expand All @@ -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 );
2 changes: 0 additions & 2 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
isBlockSelected,
isBlockMultiSelected,
isFirstMultiSelectedBlock,
getMultiSelectedBlockUids,
isTypingInBlock,
} from '../../selectors';

Expand Down Expand Up @@ -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 ),
Expand Down

0 comments on commit 64bb52e

Please sign in to comment.