diff --git a/src/model/documentselection.js b/src/model/documentselection.js index 281d5afe0..214bfd48b 100644 --- a/src/model/documentselection.js +++ b/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 ) ); } diff --git a/tests/model/documentselection.js b/tests/model/documentselection.js index 6b1da29eb..17c9dd77e 100644 --- a/tests/model/documentselection.js +++ b/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 } );