Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiselection for float elements #11748

Merged
merged 4 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason for the switch to getBlockDOMNode? Is there a hope to get rid of this this.nodes value altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that the this.nodes refer to the parent dom element which has a height = 0 for floats and I wanted the element surrounding the actual content of a block.


// prevent multi-selection from triggering when the selected block is a float
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything about this which is really specific to floats?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I thought I'd mention because it allows people to understand the reason for this code.

// 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