瀏覽代碼

Changed: model.Range and view.Range#containsRange changed parameter name and default value from strict to loose.

Szymon Cofalik 8 年之前
父節點
當前提交
e1b7889cbf

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

@@ -101,18 +101,18 @@ export default class Range {
 	 * Checks whether this range contains given {@link ~Range range}.
 	 *
 	 * @param {module:engine/model/range~Range} otherRange Range to check.
-	 * @param {Boolean} [strict=true] Whether the check is strict or loose. If the check is strict (`true`), compared range cannot
-	 * start or end at the same position as this range boundaries. If the check is loose (`false`), compared range can start, end or
+	 * @param {Boolean} [loose=false] Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
+	 * start or end at the same position as this range boundaries. If the check is loose (`true`), compared range can start, end or
 	 * even be equal to this range. Note that collapsed ranges are always compared in strict mode.
 	 * @returns {Boolean} `true` if given {@link ~Range range} boundaries are contained by this range, `false` otherwise.
 	 */
-	containsRange( otherRange, strict = true ) {
+	containsRange( otherRange, loose = false ) {
 		if ( otherRange.isCollapsed ) {
-			strict = true;
+			loose = false;
 		}
 
-		const containsStart = this.containsPosition( otherRange.start ) || ( !strict && this.start.isEqual( otherRange.start ) );
-		const containsEnd = this.containsPosition( otherRange.end ) || ( !strict && this.end.isEqual( otherRange.end ) );
+		const containsStart = this.containsPosition( otherRange.start ) || ( loose && this.start.isEqual( otherRange.start ) );
+		const containsEnd = this.containsPosition( otherRange.end ) || ( loose && this.end.isEqual( otherRange.end ) );
 
 		return containsStart && containsEnd;
 	}

+ 6 - 6
packages/ckeditor5-engine/src/view/range.js

@@ -172,19 +172,19 @@ export default class Range {
 	 * Checks whether this range contains given {@link module:engine/view/range~Range range}.
 	 *
 	 * @param {module:engine/view/range~Range} otherRange Range to check.
-	 * @param {Boolean} [strict=true] Whether the check is strict or loose. If the check is strict (`true`), compared range cannot
-	 * start or end at the same position as this range boundaries. If the check is loose (`false`), compared range can start, end or
+	 * @param {Boolean} [loose=false] Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
+	 * start or end at the same position as this range boundaries. If the check is loose (`true`), compared range can start, end or
 	 * even be equal to this range. Note that collapsed ranges are always compared in strict mode.
 	 * @returns {Boolean} `true` if given {@link module:engine/view/range~Range range} boundaries are contained by this range, `false`
 	 * otherwise.
 	 */
-	containsRange( otherRange, strict = true ) {
+	containsRange( otherRange, loose = false ) {
 		if ( otherRange.isCollapsed ) {
-			strict = true;
+			loose = false;
 		}
 
-		const containsStart = this.containsPosition( otherRange.start ) || ( !strict && this.start.isEqual( otherRange.start ) );
-		const containsEnd = this.containsPosition( otherRange.end ) || ( !strict && this.end.isEqual( otherRange.end ) );
+		const containsStart = this.containsPosition( otherRange.start ) || ( loose && this.start.isEqual( otherRange.start ) );
+		const containsEnd = this.containsPosition( otherRange.end ) || ( loose && this.end.isEqual( otherRange.end ) );
 
 		return containsStart && containsEnd;
 	}

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

@@ -394,27 +394,28 @@ describe( 'Range', () => {
 		it( 'should return true if ranges are equal and check is not strict', () => {
 			const otherRange = Range.createFromRange( range );
 
-			expect( range.containsRange( otherRange, false ) ).to.be.true;
+			expect( range.containsRange( otherRange, true ) ).to.be.true;
 		} );
 
 		it( 'should return true if ranges start at the same position and check is not strict', () => {
 			const otherRange = new Range( range.start, new Position( root, [ 2 ] ) );
 
-			expect( range.containsRange( otherRange, false ) ).to.be.true;
+			expect( range.containsRange( otherRange, true ) ).to.be.true;
 		} );
 
 		it( 'should return true if ranges end at the same position and check is not strict', () => {
 			const otherRange = new Range( new Position( root, [ 2 ] ), range.end );
 
-			expect( range.containsRange( otherRange, false ) ).to.be.true;
+			expect( range.containsRange( otherRange, true ) ).to.be.true;
 		} );
 
 		it( 'should return false if given range is collapsed and starts or ends at another range boundary', () => {
 			expect( range.containsRange( new Range( range.start, range.start ) ) ).to.be.false;
 			expect( range.containsRange( new Range( range.end, range.end ) ) ).to.be.false;
 
-			expect( range.containsRange( new Range( range.start, range.start ), false ) ).to.be.false;
-			expect( range.containsRange( new Range( range.end, range.end ), false ) ).to.be.false;
+			// Collapsed range should always be checked in strict mode.
+			expect( range.containsRange( new Range( range.start, range.start ), true ) ).to.be.false;
+			expect( range.containsRange( new Range( range.end, range.end ), true ) ).to.be.false;
 		} );
 	} );
 

+ 5 - 5
packages/ckeditor5-engine/tests/view/range.js

@@ -305,27 +305,27 @@ describe( 'Range', () => {
 		it( 'should return true if ranges are equal and check is not strict', () => {
 			const otherRange = Range.createFromRange( range );
 
-			expect( range.containsRange( otherRange, false ) ).to.be.true;
+			expect( range.containsRange( otherRange, true ) ).to.be.true;
 		} );
 
 		it( 'should return true if ranges start at the same position and check is not strict', () => {
 			const otherRange = new Range( range.start, afterX );
 
-			expect( range.containsRange( otherRange, false ) ).to.be.true;
+			expect( range.containsRange( otherRange, true ) ).to.be.true;
 		} );
 
 		it( 'should return true if ranges end at the same position and check is not strict', () => {
 			const otherRange = new Range( beforeB, range.end );
 
-			expect( range.containsRange( otherRange, false ) ).to.be.true;
+			expect( range.containsRange( otherRange, true ) ).to.be.true;
 		} );
 
 		it( 'should return false if given range is collapsed and starts or ends at another range boundary', () => {
 			expect( range.containsRange( new Range( range.start, range.start ) ) ).to.be.false;
 			expect( range.containsRange( new Range( range.end, range.end ) ) ).to.be.false;
 
-			expect( range.containsRange( new Range( range.start, range.start ), false ) ).to.be.false;
-			expect( range.containsRange( new Range( range.end, range.end ), false ) ).to.be.false;
+			expect( range.containsRange( new Range( range.start, range.start ), true ) ).to.be.false;
+			expect( range.containsRange( new Range( range.end, range.end ), true ) ).to.be.false;
 		} );
 	} );