Skip to content

Commit

Permalink
Multi-select on shift+click
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 13, 2017
1 parent 65b43ca commit 2328828
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
23 changes: 21 additions & 2 deletions editor/modes/visual-editor/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import {
getMultiSelectedBlocksEndUid,
getMultiSelectedBlocks,
getMultiSelectedBlockUids,
getSelectedBlock,
} from '../../selectors';
import { insertBlock, startMultiSelect, stopMultiSelect, multiSelect } from '../../actions';
import { insertBlock, startMultiSelect, stopMultiSelect, multiSelect, selectBlock } from '../../actions';

const INSERTION_POINT_PLACEHOLDER = '[[insertion-point]]';

Expand All @@ -36,6 +37,7 @@ class VisualEditorBlockList extends Component {
this.onSelectionStart = this.onSelectionStart.bind( this );
this.onSelectionChange = this.onSelectionChange.bind( this );
this.onSelectionEnd = this.onSelectionEnd.bind( this );
this.onShiftSelection = this.onShiftSelection.bind( this );
this.onCopy = this.onCopy.bind( this );
this.onCut = this.onCut.bind( this );
this.setBlockRef = this.setBlockRef.bind( this );
Expand Down Expand Up @@ -175,6 +177,18 @@ class VisualEditorBlockList extends Component {
this.props.onStopMultiSelect();
}

onShiftSelection( uid ) {
const { selectedBlock, selectionStart, onMultiSelect, onSelect } = this.props;

if ( selectedBlock ) {
onMultiSelect( selectedBlock.uid, uid );
} else if ( selectionStart ) {
onMultiSelect( selectionStart, uid );
} else {
onSelect( uid );
}
}

appendDefaultBlock() {
const newBlock = createBlock( getDefaultBlockName() );
this.props.onInsertBlock( newBlock );
Expand Down Expand Up @@ -212,7 +226,8 @@ class VisualEditorBlockList extends Component {
key={ uid }
uid={ uid }
blockRef={ ( ref ) => this.setBlockRef( ref, uid ) }
onSelectionStart={ () => this.onSelectionStart( uid ) }
onSelectionStart={ this.onSelectionStart }
onShiftSelection={ this.onShiftSelection }
/>
);
} ) }
Expand Down Expand Up @@ -243,6 +258,7 @@ export default connect(
selectionEnd: getMultiSelectedBlocksEndUid( state ),
multiSelectedBlocks: getMultiSelectedBlocks( state ),
multiSelectedBlockUids: getMultiSelectedBlockUids( state ),
selectedBlock: getSelectedBlock( state ),
} ),
( dispatch ) => ( {
onInsertBlock( block ) {
Expand All @@ -257,6 +273,9 @@ export default connect(
onMultiSelect( start, end ) {
dispatch( multiSelect( start, end ) );
},
onSelect( uid ) {
dispatch( selectBlock( uid ) );
},
onRemove( uids ) {
dispatch( { type: 'REMOVE_BLOCKS', uids } );
},
Expand Down
11 changes: 9 additions & 2 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,15 @@ class VisualEditorBlock extends Component {
return;
}

this.props.onSelectionStart();
this.props.onSelect();
if ( event.shiftKey ) {
if ( ! this.props.isSelected ) {
this.props.onShiftSelection( this.props.uid );
event.preventDefault();
}
} else {
this.props.onSelectionStart( this.props.uid );
this.props.onSelect();
}
}

onKeyDown( event ) {
Expand Down

0 comments on commit 2328828

Please sign in to comment.