Skip to content

Commit

Permalink
Block List: Restore missing selectionStart props (#5046)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Feb 16, 2018
1 parent a961fef commit 302af94
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions editor/components/block-list/layout.js
Expand Up @@ -27,6 +27,7 @@ import BlockListBlock from './block';
import BlockSelectionClearer from '../block-selection-clearer';
import DefaultBlockAppender from '../default-block-appender';
import {
getMultiSelectedBlocksEndUid,
isSelectionEnabled,
isMultiSelecting,
} from '../../store/selectors';
Expand Down Expand Up @@ -128,20 +129,28 @@ class BlockListLayout extends Component {
window.addEventListener( 'mouseup', this.onSelectionEnd );
}

/**
* Handles multi-selection changes in response to pointer move.
*
* @param {string} uid Block under cursor in multi-select drag.
*/
onSelectionChange( uid ) {
const { onMultiSelect, selectionStart, selectionEnd } = this.props;
const { onMultiSelect, multiSelectionEndUID } = this.props;
const { selectionAtStart } = this;
const isAtStart = selectionAtStart === uid;

if ( ! selectionAtStart || ! this.props.isSelectionEnabled ) {
return;
}

if ( isAtStart && selectionStart ) {
// If multi-selecting and cursor extent returns to the start of
// selection, cancel multi-select.
if ( isAtStart && this.props.isMultiSelecting ) {
onMultiSelect( null, null );
}

if ( ! isAtStart && selectionEnd !== uid ) {
// Expand multi-selection to block under cursor.
if ( ! isAtStart && multiSelectionEndUID !== uid ) {
onMultiSelect( selectionAtStart, uid );
}
}
Expand Down Expand Up @@ -237,6 +246,7 @@ export default connect(
// assume either multi-selection (getMultiSelectedBlocksStartUid) or
// singular-selection (getSelectedBlock) exclusively.
selectionStartUID: state.blockSelection.start,
multiSelectionEndUID: getMultiSelectedBlocksEndUid( state ),
isSelectionEnabled: isSelectionEnabled( state ),
isMultiSelecting: isMultiSelecting( state ),
} ),
Expand Down

0 comments on commit 302af94

Please sign in to comment.