Skip to content

Commit

Permalink
Fix multiselection for float elements (#11748)
Browse files Browse the repository at this point in the history
* Fix multiselection for float elements

* Update changelog

* Add a comment to explain the fix

* revert unrelated change
  • Loading branch information
youknowriad authored Nov 12, 2018
1 parent 96df8ee commit 4c487f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 7.0.1 (Unreleased)

### Bug Fixes

- Fix multi-selection triggering too often when using floated blocks.

## 7.0.0 (2018-11-12)

### Breaking Change
Expand Down
12 changes: 10 additions & 2 deletions packages/editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { compose } from '@wordpress/compose';
*/
import BlockListBlock from './block';
import BlockListAppender from '../block-list-appender';
import { getBlockDOMNode } from '../../utils/dom';

class BlockList extends Component {
constructor( props ) {
Expand Down Expand Up @@ -78,8 +79,15 @@ class BlockList extends Component {
this.props.onStartMultiSelect();
}

const boundaries = this.nodes[ this.selectionAtStart ].getBoundingClientRect();
const y = clientY - boundaries.top;
const blockContentBoundaries = getBlockDOMNode( this.selectionAtStart ).getBoundingClientRect();

// prevent multi-selection from triggering when the selected block is a float
// and the cursor is still between the top and the bottom of the block.
if ( clientY >= blockContentBoundaries.top && clientY <= blockContentBoundaries.bottom ) {
return;
}

const y = clientY - blockContentBoundaries.top;
const key = findLast( this.coordMapKeys, ( coordY ) => coordY < y );

this.onSelectionChange( this.coordMap[ key ] );
Expand Down

0 comments on commit 4c487f7

Please sign in to comment.