Przeglądaj źródła

Removed loose option for Renge#getJoined().

Kuba Niegowski 5 lat temu
rodzic
commit
7c93282bcd

+ 3 - 6
packages/ckeditor5-engine/src/model/range.js

@@ -278,7 +278,7 @@ export default class Range {
 
 	/**
 	 * Returns a range created by joining this {@link ~Range range} with the given {@link ~Range range}.
-	 * If ranges have no common part, returns `null`, even if they have equal start/end position.
+	 * If ranges have no common part, returns `null`.
 	 *
 	 * Examples:
 	 *
@@ -299,15 +299,12 @@ export default class Range {
 	 *		transformed = range.getJoined( otherRange ); // range from [ 2, 7 ] to [ 5 ]
 	 *
 	 * @param {module:engine/model/range~Range} otherRange Range to be joined.
-	 * @param {Boolean} [loose=false] Whether the intersection check is loose or strict. If the check is strict (`false`),
-	 * ranges are tested for intersection only. If the check is loose (`true`), compared range is also checked if it's "touching"
-	 * current range.
 	 * @returns {module:engine/model/range~Range|null} A sum of given ranges or `null` if ranges have no common part.
 	 */
-	getJoined( otherRange, loose = false ) {
+	getJoined( otherRange ) {
 		let shouldJoin = this.isIntersecting( otherRange );
 
-		if ( loose && !shouldJoin ) {
+		if ( !shouldJoin ) {
 			if ( this.start.isBefore( otherRange.start ) ) {
 				shouldJoin = this.end.isTouching( otherRange.start );
 			} else {

+ 6 - 13
packages/ckeditor5-engine/tests/model/range.js

@@ -796,13 +796,6 @@ describe( 'Range', () => {
 			range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 5, 4 ] ) );
 		} );
 
-		it( 'should return null if ranges do not intersect', () => {
-			const otherRange = new Range( new Position( root, [ 5, 4 ] ), new Position( root, [ 7 ] ) );
-			const sum = range.getJoined( otherRange );
-
-			expect( sum ).to.be.null;
-		} );
-
 		it( 'should return a range spanning both of the ranges - original range contains the other range', () => {
 			const otherRange = new Range( new Position( root, [ 4 ] ), new Position( root, [ 5 ] ) );
 			const sum = range.getJoined( otherRange );
@@ -832,7 +825,7 @@ describe( 'Range', () => {
 			expect( sum.isEqual( range ) ).to.be.true;
 		} );
 
-		describe( 'with `loose` option enabled', () => {
+		describe( 'with ranges "touching"', () => {
 			beforeEach( () => {
 				prepareRichRoot( root );
 			} );
@@ -840,7 +833,7 @@ describe( 'Range', () => {
 			it( 'should return null if ranges are not intersecting nor touching', () => {
 				const range = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
 				const otherRange = new Range( new Position( root, [ 3, 1 ] ), new Position( root, [ 3, 2 ] ) );
-				const sum = range.getJoined( otherRange, true );
+				const sum = range.getJoined( otherRange );
 
 				expect( sum ).to.be.null;
 			} );
@@ -848,7 +841,7 @@ describe( 'Range', () => {
 			it( 'should return a range spanning both of the ranges - original range end is equal to other range start position', () => {
 				const range = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
 				const otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 3, 2 ] ) );
-				const sum = range.getJoined( otherRange, true );
+				const sum = range.getJoined( otherRange );
 
 				expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
 				expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );
@@ -857,7 +850,7 @@ describe( 'Range', () => {
 			it( 'should return a range spanning both of the ranges - original range start is equal to other range end position', () => {
 				const range = new Range( new Position( root, [ 3 ] ), new Position( root, [ 3, 2 ] ) );
 				const otherRange = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
-				const sum = range.getJoined( otherRange, true );
+				const sum = range.getJoined( otherRange );
 
 				expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
 				expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );
@@ -866,7 +859,7 @@ describe( 'Range', () => {
 			it( 'should return a range spanning both of the ranges - original range is touching other range on the right side', () => {
 				const range = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 3 ] ) );
 				const otherRange = new Range( new Position( root, [ 3, 0 ] ), new Position( root, [ 3, 2 ] ) );
-				const sum = range.getJoined( otherRange, true );
+				const sum = range.getJoined( otherRange );
 
 				expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
 				expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );
@@ -875,7 +868,7 @@ describe( 'Range', () => {
 			it( 'should return a range spanning both of the ranges - original range is touching other range on the left side', () => {
 				const range = new Range( new Position( root, [ 1, 0 ] ), new Position( root, [ 3, 2 ] ) );
 				const otherRange = new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 0, 2 ] ) );
-				const sum = range.getJoined( otherRange, true );
+				const sum = range.getJoined( otherRange );
 
 				expect( sum.start.path ).to.deep.equal( [ 0, 1 ] );
 				expect( sum.end.path ).to.deep.equal( [ 3, 2 ] );

+ 1 - 1
packages/ckeditor5-undo/src/basecommand.js

@@ -186,7 +186,7 @@ function normalizeRanges( ranges ) {
 
 	for ( let i = 1; i < ranges.length; i++ ) {
 		const previousRange = ranges[ i - 1 ];
-		const joinedRange = previousRange.getJoined( ranges[ i ], true );
+		const joinedRange = previousRange.getJoined( ranges[ i ] );
 
 		if ( joinedRange ) {
 			// Replace the ranges on the list with the new joined range.