ソースを参照

Renamed `SAME` to lower case.

Oskar Wrobel 9 年 前
コミット
2a555b94ed

+ 9 - 9
packages/ckeditor5-engine/src/model/delta/basic-transformations.js

@@ -64,7 +64,7 @@ addTransformationCase( MoveDelta, MergeDelta, ( a, b, isStrong ) => {
 
 	const operateInSameParent =
 		a.sourcePosition.root == b.position.root &&
-		compareArrays( a.sourcePosition.getParentPath(), b.position.getParentPath() ) === 'SAME';
+		compareArrays( a.sourcePosition.getParentPath(), b.position.getParentPath() ) === 'same';
 
 	const mergeInsideMoveRange = a.sourcePosition.offset <= b.position.offset && a.sourcePosition.offset + a.howMany > b.position.offset;
 
@@ -96,7 +96,7 @@ addTransformationCase( MergeDelta, MoveDelta, ( a, b, isStrong ) => {
 
 	const operateInSameParent =
 		a.position.root == b.sourcePosition.root &&
-		compareArrays( a.position.getParentPath(), b.sourcePosition.getParentPath() ) === 'SAME';
+		compareArrays( a.position.getParentPath(), b.sourcePosition.getParentPath() ) === 'same';
 
 	const mergeInsideMoveRange = b.sourcePosition.offset <= a.position.offset && b.sourcePosition.offset + b.howMany > a.position.offset;
 
@@ -113,7 +113,7 @@ addTransformationCase( SplitDelta, SplitDelta, ( a, b, isStrong ) => {
 	const pathB = b.position.getParentPath();
 
 	// The special case is for splits inside the same parent.
-	if ( compareArrays( pathA, pathB ) == 'SAME' ) {
+	if ( compareArrays( pathA, pathB ) == 'same' ) {
 		if ( a.position.offset == b.position.offset ) {
 			// We are applying split at the position where split already happened. Additional split is not needed.
 			return [ noDelta() ];
@@ -167,7 +167,7 @@ addTransformationCase( SplitDelta, SplitDelta, ( a, b, isStrong ) => {
 addTransformationCase( SplitDelta, UnwrapDelta, ( a, b, isStrong ) => {
 	// If incoming split delta tries to split a node that just got unwrapped, there is actually nothing to split,
 	// so we discard that delta.
-	if ( compareArrays( b.position.path, a.position.getParentPath() ) === 'SAME' ) {
+	if ( compareArrays( b.position.path, a.position.getParentPath() ) === 'same' ) {
 		return [ noDelta() ];
 	}
 
@@ -179,12 +179,12 @@ addTransformationCase( SplitDelta, WrapDelta, ( a, b, isStrong ) => {
 	// If split is applied at the position between wrapped nodes, we cancel the split as it's results may be unexpected and
 	// very weird. Even if we do some "magic" we don't know what really are users' expectations.
 
-	const operateInSameParent = compareArrays( a.position.getParentPath(), b.range.start.getParentPath() ) === 'SAME';
+	const operateInSameParent = compareArrays( a.position.getParentPath(), b.range.start.getParentPath() ) === 'same';
 	const splitInsideWrapRange = b.range.start.offset < a.position.offset && b.range.end.offset >= a.position.offset;
 
 	if ( operateInSameParent && splitInsideWrapRange ) {
 		return [ noDelta() ];
-	} else if ( compareArrays( a.position.getParentPath(), b.range.end.getShiftedBy( -1 ).path ) === 'SAME' ) {
+	} else if ( compareArrays( a.position.getParentPath(), b.range.end.getShiftedBy( -1 ).path ) === 'same' ) {
 		// Split position is directly inside the last node from wrap range.
 		// If that's the case, we manually change split delta so it will "target" inside the wrapping element.
 		// By doing so we will be inserting split node right to the original node which feels natural and is a good UX.
@@ -229,7 +229,7 @@ addTransformationCase( SplitDelta, WrapDelta, ( a, b, isStrong ) => {
 addTransformationCase( UnwrapDelta, SplitDelta, ( a, b, isStrong ) => {
 	// If incoming unwrap delta tries to unwrap node that got split we should unwrap the original node and the split copy.
 	// This can be achieved either by reverting split and applying unwrap to singular node, or creating additional unwrap delta.
-	if ( compareArrays( a.position.path, b.position.getParentPath() ) === 'SAME' ) {
+	if ( compareArrays( a.position.path, b.position.getParentPath() ) === 'same' ) {
 		const transformed = [
 			b.getReversed(),
 			a.clone()
@@ -266,7 +266,7 @@ addTransformationCase( WrapDelta, SplitDelta, ( a, b, isStrong ) => {
 	// If incoming wrap delta tries to wrap range that contains split position, we have to cancel the split and apply
 	// the wrap. Since split was already applied, we have to revert it.
 
-	const operateInSameParent = compareArrays( a.range.start.getParentPath(), b.position.getParentPath() ) === 'SAME';
+	const operateInSameParent = compareArrays( a.range.start.getParentPath(), b.position.getParentPath() ) === 'same';
 	const splitInsideWrapRange = a.range.start.offset < b.position.offset && a.range.end.offset >= b.position.offset;
 
 	if ( operateInSameParent && splitInsideWrapRange ) {
@@ -274,7 +274,7 @@ addTransformationCase( WrapDelta, SplitDelta, ( a, b, isStrong ) => {
 			b.getReversed(),
 			a.clone()
 		];
-	} else if ( compareArrays( b.position.getParentPath(), a.range.end.getShiftedBy( -1 ).path ) === 'SAME' ) {
+	} else if ( compareArrays( b.position.getParentPath(), a.range.end.getShiftedBy( -1 ).path ) === 'same' ) {
 		const delta = a.clone();
 
 		// Move wrapping element insert position one node further so it is after the split node insertion.

+ 1 - 1
packages/ckeditor5-engine/src/model/operation/transform.js

@@ -322,7 +322,7 @@ const ot = {
 			let aIsInside = rangeB.containsRange( rangeA ) &&
 				( rangeB.containsPosition( a.targetPosition ) || rangeB.start.isEqual( a.targetPosition ) || rangeB.end.isEqual( a.targetPosition ) );
 
-			if ( common !== null && ( aCompB === 'extension' || ( aCompB === 'SAME' && isStrong ) || aIsInside ) && !bTargetsToA ) {
+			if ( common !== null && ( aCompB === 'extension' || ( aCompB === 'same' && isStrong ) || aIsInside ) && !bTargetsToA ) {
 				// Here we do not need to worry that newTargetPosition is inside moved range, because that
 				// would mean that the MoveOperation targets into itself, and that is incorrect operation.
 				// Instead, we calculate the new position of that part of original range.

+ 7 - 7
packages/ckeditor5-engine/src/model/position.js

@@ -148,8 +148,8 @@ export default class Position {
 		const result = compareArrays( this.path, otherPosition.path );
 
 		switch ( result ) {
-			case 'SAME':
-				return 'SAME';
+			case 'same':
+				return 'same';
 
 			case 'prefix':
 				return 'before';
@@ -209,7 +209,7 @@ export default class Position {
 			return transformed;
 		}
 
-		if ( compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
+		if ( compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'same' ) {
 			// If nodes are removed from the node that is pointed by this position...
 			if ( deletePosition.offset < this.offset ) {
 				// And are removed from before an offset of that position...
@@ -260,7 +260,7 @@ export default class Position {
 			return transformed;
 		}
 
-		if ( compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
+		if ( compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'same' ) {
 			// If nodes are inserted in the node that is pointed by this position...
 			if ( insertPosition.offset < this.offset || ( insertPosition.offset == this.offset && insertBefore ) ) {
 				// And are inserted before an offset of that position...
@@ -369,7 +369,7 @@ export default class Position {
 	 * @returns {Boolean} True if positions are same.
 	 */
 	isEqual( otherPosition ) {
-		return this.compareWith( otherPosition ) == 'SAME';
+		return this.compareWith( otherPosition ) == 'same';
 	}
 
 	/**
@@ -386,7 +386,7 @@ export default class Position {
 		let compare = this.compareWith( otherPosition );
 
 		switch ( compare ) {
-			case 'SAME':
+			case 'same':
 				return true;
 
 			case 'before':
@@ -641,7 +641,7 @@ export default class Position {
 }
 
 /**
- * A flag indicating whether this position is `'before'` or `'after'` or `'SAME'` as given position.
+ * A flag indicating whether this position is `'before'` or `'after'` or `'same'` as given position.
  * If positions are in different roots `'different'` flag is returned.
  *
  * @typedef {String} engine.model.PositionRelation

+ 1 - 1
packages/ckeditor5-engine/src/model/selection.js

@@ -338,7 +338,7 @@ export default class Selection {
 
 		const newFocus = Position.createAt( nodeOrPosition, offset );
 
-		if ( newFocus.compareWith( this.focus ) == 'SAME' ) {
+		if ( newFocus.compareWith( this.focus ) == 'same' ) {
 			return;
 		}
 

+ 2 - 2
packages/ckeditor5-engine/src/view/position.js

@@ -132,7 +132,7 @@ export default class Position {
 	 */
 	compareWith( otherPosition ) {
 		if ( this.isEqual( otherPosition ) ) {
-			return 'SAME';
+			return 'same';
 		}
 
 		// If positions have same parent.
@@ -269,7 +269,7 @@ export default class Position {
 }
 
 /**
- * A flag indicating whether this position is `'before'` or `'after'` or `'SAME'` as given position.
+ * A flag indicating whether this position is `'before'` or `'after'` or `'same'` as given position.
  * If positions are in different roots `'different'` flag is returned.
  *
  * @typedef {String} engine.view.PositionRelation

+ 2 - 2
packages/ckeditor5-engine/tests/_utils/model.js

@@ -313,12 +313,12 @@ function writeSelection( currentPosition, selection ) {
 	const range = selection.getFirstRange();
 
 	// Handle end of the selection.
-	if ( !selection.isCollapsed && range.end.compareWith( currentPosition ) == 'SAME' ) {
+	if ( !selection.isCollapsed && range.end.compareWith( currentPosition ) == 'same' ) {
 		return '</selection>';
 	}
 
 	// Handle no match.
-	if ( range.start.compareWith( currentPosition ) != 'SAME' ) {
+	if ( range.start.compareWith( currentPosition ) != 'same' ) {
 		return '';
 	}
 

+ 2 - 2
packages/ckeditor5-engine/tests/model/liveselection.js

@@ -171,8 +171,8 @@ describe( 'LiveSelection', () => {
 
 			selection.setFocus( endPos );
 
-			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( endPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
 		} );
 
 		it( 'detaches the range it replaces', () => {

+ 2 - 2
packages/ckeditor5-engine/tests/model/position.js

@@ -462,11 +462,11 @@ describe( 'position', () => {
 	} );
 
 	describe( 'compareWith', () => {
-		it( 'should return SAME if positions are same', () => {
+		it( 'should return same if positions are same', () => {
 			const position = new Position( root, [ 1, 2, 3 ] );
 			const compared = new Position( root, [ 1, 2, 3 ] );
 
-			expect( position.compareWith( compared ) ).to.equal( 'SAME' );
+			expect( position.compareWith( compared ) ).to.equal( 'same' );
 		} );
 
 		it( 'should return before if the position is before compared one', () => {

+ 18 - 18
packages/ckeditor5-engine/tests/model/selection.js

@@ -317,8 +317,8 @@ describe( 'Selection', () => {
 
 			selection.setFocus( endPos );
 
-			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( endPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
 		} );
 
 		it( 'makes existing collapsed selection a backward selection', () => {
@@ -329,8 +329,8 @@ describe( 'Selection', () => {
 
 			selection.setFocus( endPos );
 
-			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( endPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( endPos ) ).to.equal( 'same' );
 			expect( selection.isBackward ).to.be.true;
 		} );
 
@@ -343,8 +343,8 @@ describe( 'Selection', () => {
 
 			selection.setFocus( newEndPos );
 
-			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
 		} );
 
 		it( 'makes existing non-collapsed selection a backward selection', () => {
@@ -356,8 +356,8 @@ describe( 'Selection', () => {
 
 			selection.setFocus( newEndPos );
 
-			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( startPos ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
 			expect( selection.isBackward ).to.be.true;
 		} );
 
@@ -370,8 +370,8 @@ describe( 'Selection', () => {
 
 			selection.setFocus( newEndPos );
 
-			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
 			expect( selection.isBackward ).to.be.false;
 		} );
 
@@ -384,8 +384,8 @@ describe( 'Selection', () => {
 
 			selection.setFocus( newEndPos );
 
-			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( endPos ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
 			expect( selection.isBackward ).to.be.true;
 		} );
 
@@ -410,11 +410,11 @@ describe( 'Selection', () => {
 			const ranges = Array.from( selection.getRanges() );
 
 			expect( ranges ).to.have.lengthOf( 2 );
-			expect( ranges[ 0 ].start.compareWith( startPos1 ) ).to.equal( 'SAME' );
-			expect( ranges[ 0 ].end.compareWith( endPos1 ) ).to.equal( 'SAME' );
+			expect( ranges[ 0 ].start.compareWith( startPos1 ) ).to.equal( 'same' );
+			expect( ranges[ 0 ].end.compareWith( endPos1 ) ).to.equal( 'same' );
 
-			expect( selection.anchor.compareWith( startPos2 ) ).to.equal( 'SAME' );
-			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'SAME' );
+			expect( selection.anchor.compareWith( startPos2 ) ).to.equal( 'same' );
+			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
 			expect( selection.isBackward ).to.be.true;
 
 			expect( spy.calledOnce ).to.be.true;
@@ -428,7 +428,7 @@ describe( 'Selection', () => {
 
 			selection.setFocus( startPos );
 
-			expect( selection.focus.compareWith( startPos ) ).to.equal( 'SAME' );
+			expect( selection.focus.compareWith( startPos ) ).to.equal( 'same' );
 			expect( selection.isCollapsed ).to.be.true;
 		} );
 
@@ -443,7 +443,7 @@ describe( 'Selection', () => {
 			selection.setFocus( root, 'end' );
 
 			expect( spy.calledOnce ).to.be.true;
-			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'SAME' );
+			expect( selection.focus.compareWith( newEndPos ) ).to.equal( 'same' );
 		} );
 	} );
 

+ 2 - 2
packages/ckeditor5-engine/tests/view/position.js

@@ -257,12 +257,12 @@ describe( 'Position', () => {
 	} );
 
 	describe( 'compareWith', () => {
-		it( 'should return SAME if positions are same', () => {
+		it( 'should return same if positions are same', () => {
 			const root = new Node();
 			const position = new Position( root, 0 );
 			const compared = new Position( root, 0 );
 
-			expect( position.compareWith( compared ) ).to.equal( 'SAME' );
+			expect( position.compareWith( compared ) ).to.equal( 'same' );
 		} );
 
 		it( 'should return before if the position is before compared one', () => {