Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Do not fix graveyard range if it would intersect with existing select…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
jodator committed Mar 30, 2020
1 parent f0902fb commit bc94b5c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ class LiveSelection extends Selection {
liveRange.detach();

// If nearest valid selection range has been found - add it in the place of old range.
if ( selectionRange ) {
if ( selectionRange && !isIntersecting( this._ranges, selectionRange ) ) {
// Check the range, convert it to live range, bind events, etc.
const newRange = this._prepareRange( selectionRange );

Expand Down Expand Up @@ -1190,3 +1190,15 @@ function clearAttributesStoredInElement( model, batch ) {
}
}
}

// Checks if range intersects with any given ranges.
function isIntersecting( ranges, selectionRange ) {
for ( let i = 0; i < ranges.length; i++ ) {
if ( selectionRange.isIntersecting( ranges[ i ] ) ) {
// It is also fine - as we can have multiple ranges in the selection.
return true;
}
}

return false;
}

0 comments on commit bc94b5c

Please sign in to comment.