浏览代码

Removed createFromPositionAndShift, use Range.createFromPositionAndOffset instead.

Piotr Jasiun 10 年之前
父节点
当前提交
355bceba49

+ 2 - 3
packages/ckeditor5-utils/src/document/operation/insertoperation.js

@@ -9,9 +9,8 @@ CKEDITOR.define( [
 	'document/operation/operation',
 	'document/nodelist',
 	'document/range',
-	'document/position',
 	'document/operation/removeoperation'
-], ( Operation, NodeList, Range, Position ) => {
+], ( Operation, NodeList, Range ) => {
 	/**
 	 * Operation to insert list of nodes on the given position in the tree data model.
 	 *
@@ -66,7 +65,7 @@ CKEDITOR.define( [
 			this.position.parent.insertChildren( this.position.offset, this.nodeList );
 
 			return {
-				range: new Range( this.position, Position.createFromPositionAndShift( this.position, this.nodeList.length ) )
+				range: Range.createFromPositionAndOffset( this.position, this.nodeList.length )
 			};
 		}
 	}

+ 2 - 3
packages/ckeditor5-utils/src/document/operation/moveoperation.js

@@ -8,11 +8,10 @@
 CKEDITOR.define( [
 	'document/operation/operation',
 	'document/nodelist',
-	'document/position',
 	'document/range',
 	'ckeditorerror',
 	'utils'
-], ( Operation, NodeList, Position, Range, CKEditorError, utils ) => {
+], ( Operation, NodeList, Range, CKEditorError, utils ) => {
 	/**
 	 * Operation to move list of subsequent nodes from one position in the document to another.
 	 *
@@ -131,7 +130,7 @@ CKEDITOR.define( [
 
 			return {
 				sourcePosition: this.sourcePosition,
-				range: new Range( this.targetPosition, Position.createFromPositionAndShift( this.targetPosition, this.howMany ) )
+				range: Range.createFromPositionAndOffset( this.targetPosition, this.howMany )
 			};
 		}
 	}

+ 0 - 19
packages/ckeditor5-utils/src/document/position.js

@@ -220,25 +220,6 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 			return transformed;
 		}
 
-		/**
-		 * Returns a new position on the same level as reference position, but with offset shifted left or right.
-		 *
-		 *		 const pos = new Position( [ 1, 2, 8 ], root );
-		 *
-		 *		 Position.createFromPositionAndShift( pos, -3 ) // [ 1, 2, 5 ]
-		 *		 Position.createFromPositionAndShift( pos, 5 )  // [ 1, 2, 13 ]
-		 *
-		 * @param {document.Position} referencePosition Reference position.
-		 * @param {Number} shift Offset shift.
-		 * @returns {document.Position}
-		 */
-		static createFromPositionAndShift( referencePosition, shift ) {
-			let newPosition = new Position( utils.clone( referencePosition.path ), referencePosition.root );
-			newPosition.offset = newPosition.offset + shift;
-
-			return newPosition;
-		}
-
 		/**
 		 * Returns this position after being updated by inserting `howMany` nodes at `insertPosition`.
 		 *

+ 0 - 7
packages/ckeditor5-utils/tests/document/position.js

@@ -98,13 +98,6 @@ describe( 'position', () => {
 		expect( Position.createFromParentAndOffset( li1, 3 ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 3 ] );
 	} );
 
-	it( 'should create position from another position and shift', () => {
-		const pos = Position.createFromParentAndOffset( ul, 1 );
-
-		expect( Position.createFromPositionAndShift( pos, -1 ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0 ] );
-		expect( Position.createFromPositionAndShift( pos, 1 ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 2 ] );
-	} );
-
 	it( 'should create positions before elements', () => {
 		expect( Position.createBefore( p ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );