Browse Source

Fixed conditions on checking ranges when fixing graveyard selection.

Maciej Gołaszewski 5 years ago
parent
commit
b19c59f320

+ 5 - 5
packages/ckeditor5-engine/src/model/documentselection.js

@@ -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 );
 
@@ -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 ) );
 }

+ 3 - 3
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -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 ] ) )
@@ -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
 				} );