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

Commit

Permalink
Fixed conditions on checking ranges when fixing graveyard selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Apr 14, 2020
1 parent ac8078d commit e4fea16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,9 @@ class LiveSelection extends Selection {
liveRange.detach();

// If nearest valid selection range has been found - add it in the place of old range.
// If range is intersecting with other selection ranges then it is probably due to contents
// If range is equal to any other selection ranges then it is probably due to contents
// of a multi-range selection being removed. See ckeditor/ckeditor5#6501.
if ( selectionRange && !isRangeIntersectingWithSelection( selectionRange, this ) ) {
if ( selectionRange && !isRangeCollidingWithSelection( selectionRange, this ) ) {
// Check the range, convert it to live range, bind events, etc.
const newRange = this._prepareRange( selectionRange );

Expand Down Expand Up @@ -1192,7 +1192,7 @@ function clearAttributesStoredInElement( model, batch ) {
}
}

// Checks if range intersects with any of selection ranges.
function isRangeIntersectingWithSelection( range, selection ) {
return !selection._ranges.every( selectionRange => !range.isIntersecting( selectionRange ) );
// Checks if range collides with any of selection ranges.
function isRangeCollidingWithSelection( range, selection ) {
return !selection._ranges.every( selectionRange => !range.isEqual( selectionRange ) );
}
6 changes: 3 additions & 3 deletions tests/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ describe( 'DocumentSelection', () => {
expect( selection.getFirstPosition().path ).to.deep.equal( [ 0, 0 ] );
} );

it( 'does not break if multi-range selection is inside text nodes', () => {
it( 'handles multi-range selection in a text node by merging it into one range (resulting in collapsed ranges)', () => {
const ranges = [
new Range( new Position( root, [ 1, 1 ] ), new Position( root, [ 1, 2 ] ) ),
new Range( new Position( root, [ 1, 3 ] ), new Position( root, [ 1, 4 ] ) )
Expand All @@ -1796,12 +1796,12 @@ describe( 'DocumentSelection', () => {
)
);

expect( selection.rangeCount ).to.equal( 2 );
expect( selection.rangeCount ).to.equal( 1 );
expect( selection.getFirstPosition().path ).to.deep.equal( [ 1, 1 ] );
expect( selection.getLastPosition().path ).to.deep.equal( [ 1, 1 ] );
} );

it( 'does not break if multi-range selection is set on object nodes and resulting ranges will intersect', () => {
it( 'handles multi-range selection on object nodes by merging it into one range (resulting in non-collapsed ranges)', () => {
model.schema.register( 'outer', {
isObject: true
} );
Expand Down

0 comments on commit e4fea16

Please sign in to comment.