Skip to content

Commit

Permalink
Fix selection in Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 4, 2019
1 parent eb668d3 commit 7a9ce87
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,20 @@ class BlockList extends Component {
const selection = window.getSelection();

// If no selection is found, end multi selection.
if ( ! selection.rangeCount ) {
if ( ! selection.rangeCount || selection.isCollapsed ) {
this.props.onStopMultiSelect();
return;
}

const { startContainer, endContainer } = selection.getRangeAt( 0 );
const startEl = this.ref.current.querySelector(
`[data-block="${ this.startClientId }"]`
);

// We need the container where mouse selection is released, not where
// it is initiated pressed.
let endEl = startEl.contains( startContainer ) ?
endContainer :
startContainer;
let { focusNode } = selection;
let clientId;

// Find the client ID of the block where the selection ends.
do {
endEl = endEl.parentElement;
focusNode = focusNode.parentElement;
} while (
endEl &&
! ( clientId = endEl.getAttribute( 'data-block' ) )
focusNode &&
! ( clientId = focusNode.getAttribute( 'data-block' ) )
);

// If the final selection doesn't leave the block, there is no multi
Expand Down

0 comments on commit 7a9ce87

Please sign in to comment.