Ver código fonte

Position.constructor change the order of parameters.

Szymon Cofalik 10 anos atrás
pai
commit
a11a4b190e

+ 24 - 24
packages/ckeditor5-utils/src/document/position.js

@@ -21,11 +21,28 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 		/**
 		 * Creates a position.
 		 *
-		 * @param {Array.<Number>} path Position path. Must contain at least one item. See {@link #path} property for more information.
 		 * @param {document.RootElement} root Root element for the path. Note that this element can not have a parent.
+		 * @param {Array.<Number>} path Position path. Must contain at least one item. See {@link #path} property for more information.
 		 * @constructor
 		 */
-		constructor( path, root ) {
+		constructor( root, path ) {
+			if ( !( root instanceof RootElement ) ) {
+				/**
+				 * Position root has to be an instance of RootElement.
+				 *
+				 * @error position-root-not-rootelement
+				 * @param root
+				 */
+				throw new CKEditorError( 'position-root-not-rootelement: Position root has to be an instance of RootElement.', { root: root } );
+			}
+
+			/**
+			 * Root element for the path. Note that this element can not have a parent.
+			 *
+			 * @type {document.RootElement}
+			 */
+			this.root = root;
+
 			if ( !( path instanceof Array ) || path.length === 0 ) {
 				/**
 				 * Position path must be an Array with at least one item.
@@ -54,23 +71,6 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 			 * @type {Number[]}
 			 */
 			this.path = path;
-
-			if ( !( root instanceof RootElement ) ) {
-				/**
-				 * Position root has to be an instance of RootElement.
-				 *
-				 * @error position-root-not-rootelement
-				 * @param root
-				 */
-				throw new CKEditorError( 'position-root-not-rootelement: Position root has to be an instance of RootElement.', { root: root } );
-			}
-
-			/**
-			 * Root element for the path. Note that this element can not have a parent.
-			 *
-			 * @type {document.RootElement}
-			 */
-			this.root = root;
 		}
 
 		/**
@@ -135,7 +135,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 		 * @returns {document.Position} Cloned {@link document.Position position}.
 		 */
 		clone() {
-			return new Position( this.path.slice(), this.root );
+			return new Position( this.root, this.path.slice() );
 		}
 
 		/**
@@ -406,7 +406,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 
 			path.push( offset );
 
-			return new Position( path, parent.root );
+			return new Position( parent.root, path );
 		}
 
 		/**
@@ -419,9 +419,9 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 		 *
 		 * Example:
 		 *
-		 * 	let original = new Position( [ 2, 3, 1 ], root );
-		 * 	let source = new Position( [ 2, 2 ], root );
-		 * 	let target = new Position( [ 1, 1, 3 ], otherRoot );
+		 * 	let original = new Position( root, [ 2, 3, 1 ] );
+		 * 	let source = new Position( root, [ 2, 2 ] );
+		 * 	let target = new Position( otherRoot, [ 1, 1, 3 ] );
 		 * 	let combined = original.getCombined( source, target );
 		 * 	// combined.path is [ 1, 1, 4, 1 ], combined.root is otherRoot
 		 *

+ 11 - 11
packages/ckeditor5-utils/src/document/range.js

@@ -80,16 +80,16 @@ CKEDITOR.define( [ 'document/position', 'document/positioniterator', 'utils' ],
 		 *
 		 * Examples:
 		 *
-		 * 	let range = new Range( new Position( [ 2, 7 ], root ), new Position( [ 4, 0, 1 ], root ) );
-		 * 	let otherRange = new Range( new Position( [ 1 ], root ), new Position( [ 5 ], root ) );
+		 * 	let range = new Range( new Position( root, [ 2, 7 ] ), new Position( root, [ 4, 0, 1 ] ) );
+		 * 	let otherRange = new Range( new Position( root, [ 1 ] ), new Position( root, [ 5 ] ) );
 		 * 	let transformed = range.getDifference( otherRange );
 		 * 	// transformed array has no ranges because `otherRange` contains `range`
 		 *
-		 * 	otherRange = new Range( new Position( [ 1 ], root ), new Position( [ 3 ], root ) );
+		 * 	otherRange = new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) );
 		 * 	transformed = range.getDifference( otherRange );
 		 * 	// transformed array has one range: from [ 3 ] to [ 4, 0, 1 ]
 		 *
-		 * 	otherRange = new Range( new Position( [ 3 ], root ), new Position( [ 4 ], root ) );
+		 * 	otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 4 ] ) );
 		 * 	transformed = range.getDifference( otherRange );
 		 * 	// transformed array has two ranges: from [ 2, 7 ] to [ 3 ] and from [ 4 ] to [ 4, 0, 1 ]
 		 *
@@ -137,11 +137,11 @@ CKEDITOR.define( [ 'document/position', 'document/positioniterator', 'utils' ],
 		 *
 		 * Examples:
 		 *
-		 * 	let range = new Range( new Position( [ 2, 7 ], root ), new Position( [ 4, 0, 1 ], root ) );
-		 * 	let otherRange = new Range( new Position( [ 1 ], root ), new Position( [ 2 ], root ) );
+		 * 	let range = new Range( new Position( root, [ 2, 7 ] ), new Position( root, [ 4, 0, 1 ] ) );
+		 * 	let otherRange = new Range( new Position( root, [ 1 ] ), new Position( root, [ 2 ] ) );
 		 * 	let transformed = range.getIntersection( otherRange ); // null - ranges have no common part
 		 *
-		 * 	otherRange = new Range( new Position( [ 3 ], root ), new Position( [ 5 ], root ) );
+		 * 	otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 5 ] ) );
 		 * 	transformed = range.getIntersection( otherRange ); // range from [ 3 ] to [ 4, 0, 1 ]
 		 *
 		 * @param {document.Range} otherRange Range to check for intersection.
@@ -180,14 +180,14 @@ CKEDITOR.define( [ 'document/position', 'document/positioniterator', 'utils' ],
 		 *
 		 * Examples:
 		 *
-		 * 	let range = new Range( new Position( [ 2, 7 ], root ), new Position( [ 4, 0, 1 ], root ) );
-		 * 	let transformed = range.getTransformedByInsertion( new Position( [ 1 ], root ), 2 );
+		 * 	let range = new Range( new Position( root, [ 2, 7 ] ), new Position( root, [ 4, 0, 1 ] ) );
+		 * 	let transformed = range.getTransformedByInsertion( new Position( root, [ 1 ] ), 2 );
 		 * 	// transformed array has one range from [ 4, 7 ] to [ 6, 0, 1 ]
 		 *
-		 * 	transformed = range.getTransformedByInsertion( new Position( [ 3, 2 ], root ), 4 );
+		 * 	transformed = range.getTransformedByInsertion( new Position( root, [ 3, 2 ] ), 4 );
 		 * 	// transformed array has two ranges: from [ 2, 7 ] to [ 3, 2 ] and from [ 3, 6 ] to [ 4, 0, 1 ]
 		 *
-		 * 	transformed = range.getTransformedByInsertion( new Position( [ 3, 2 ], root ), 4, true );
+		 * 	transformed = range.getTransformedByInsertion( new Position( root, [ 3, 2 ] ), 4, true );
 		 * 	// transformed array has one range which is equal to `range`. This is because of spreadOnlyOnSameLevel flag.
 		 *
 		 * @param {document.Position} insertPosition Position where nodes are inserted.

+ 3 - 3
packages/ckeditor5-utils/tests/document/deltas/insertdelta.js

@@ -27,7 +27,7 @@ describe( 'Transaction', () => {
 	} );
 
 	it( 'should insert text', () => {
-		const position = new Position( [ 0 ], root );
+		const position = new Position( root, [ 0 ] );
 		doc.createTransaction().insert( position, 'foo' );
 
 		expect( root.getChildCount() ).to.equal( 3 );
@@ -37,10 +37,10 @@ describe( 'Transaction', () => {
 	} );
 
 	it( 'should be chainable', () => {
-		const position = new Position( [ 0 ], root );
+		const position = new Position( root, [ 0 ] );
 		const transaction = doc.createTransaction();
 
 		const chain = transaction.insert( position, 'foo' );
 		expect( chain ).to.equal( transaction );
 	} );
-} );
+} );

+ 5 - 5
packages/ckeditor5-utils/tests/document/deltas/mergedelta.js

@@ -43,7 +43,7 @@ describe( 'Transaction', () => {
 
 	describe( 'merge', () => {
 		it( 'should merge foo and bar into foobar', () => {
-			doc.createTransaction().merge( new Position( [ 1 ], root ) );
+			doc.createTransaction().merge( new Position( root, [ 1 ] ) );
 
 			expect( root.getChildCount() ).to.equal( 1 );
 			expect( root.getChild( 0 ).name ).to.equal( 'p' );
@@ -60,21 +60,21 @@ describe( 'Transaction', () => {
 
 		it( 'should throw if there is no element after', () => {
 			expect( () => {
-				doc.createTransaction().merge( new Position( [ 2 ], root ) );
+				doc.createTransaction().merge( new Position( root, [ 2 ] ) );
 			} ).to.throw( CKEditorError, /^transaction-merge-no-element-after/ );
 		} );
 
 		it( 'should throw if there is no element before', () => {
 			expect( () => {
-				doc.createTransaction().merge( new Position( [ 0, 2 ], root ) );
+				doc.createTransaction().merge( new Position( root, [ 0, 2 ] ) );
 			} ).to.throw( CKEditorError, /^transaction-merge-no-element-before/ );
 		} );
 
 		it( 'should be chainable', () => {
 			const transaction = doc.createTransaction();
 
-			const chain = transaction.merge( new Position( [ 1 ], root ) );
+			const chain = transaction.merge( new Position( root, [ 1 ] ) );
 			expect( chain ).to.equal( transaction );
 		} );
 	} );
-} );
+} );

+ 4 - 4
packages/ckeditor5-utils/tests/document/deltas/removedelta.js

@@ -29,7 +29,7 @@ describe( 'Transaction', () => {
 
 	describe( 'remove', () => {
 		it( 'should remove one element', () => {
-			const position = new Position( [ 1 ], root );
+			const position = new Position( root, [ 1 ] );
 			doc.createTransaction().remove( position );
 
 			expect( root.getChildCount() ).to.equal( 5 );
@@ -41,7 +41,7 @@ describe( 'Transaction', () => {
 		} );
 
 		it( 'should remove 3 elements', () => {
-			const position = new Position( [ 1 ], root );
+			const position = new Position( root, [ 1 ] );
 			doc.createTransaction().remove( position, 3 );
 
 			expect( root.getChildCount() ).to.equal( 3 );
@@ -51,11 +51,11 @@ describe( 'Transaction', () => {
 		} );
 
 		it( 'should be chainable', () => {
-			const position = new Position( [ 1 ], root );
+			const position = new Position( root, [ 1 ] );
 			const transaction = doc.createTransaction();
 
 			const chain = transaction.remove( position );
 			expect( chain ).to.equal( transaction );
 		} );
 	} );
-} );
+} );

+ 5 - 5
packages/ckeditor5-utils/tests/document/deltas/splitdelta.js

@@ -42,7 +42,7 @@ describe( 'Transaction', () => {
 
 	describe( 'split', () => {
 		it( 'should split foobar to foo and bar', () => {
-			doc.createTransaction().split( new Position( [ 0, 3 ], root ) );
+			doc.createTransaction().split( new Position( root, [ 0, 3 ] ) );
 
 			expect( root.getChildCount() ).to.equal( 2 );
 
@@ -64,7 +64,7 @@ describe( 'Transaction', () => {
 		} );
 
 		it( 'should create an empty paragraph if we split at the end', () => {
-			doc.createTransaction().split( new Position( [ 0, 6 ], root ) );
+			doc.createTransaction().split( new Position( root, [ 0, 6 ] ) );
 
 			expect( root.getChildCount() ).to.equal( 2 );
 
@@ -87,15 +87,15 @@ describe( 'Transaction', () => {
 
 		it( 'should throw if we try to split a root', () => {
 			expect( () => {
-				doc.createTransaction().split( new Position( [ 0 ], root ) );
+				doc.createTransaction().split( new Position( root, [ 0 ] ) );
 			} ).to.throw( CKEditorError, /^transaction-split-root/ );
 		} );
 
 		it( 'should be chainable', () => {
 			const transaction = doc.createTransaction();
 
-			const chain = transaction.split( new Position( [ 0, 3 ], root ) );
+			const chain = transaction.split( new Position( root, [ 0, 3 ] ) );
 			expect( chain ).to.equal( transaction );
 		} );
 	} );
-} );
+} );

+ 14 - 14
packages/ckeditor5-utils/tests/document/operation/changeoperation.js

@@ -46,7 +46,7 @@ describe( 'ChangeOperation', () => {
 
 	it( 'should have proper type', () => {
 		const opp = new ChangeOperation(
-			new Range( new Position( [ 0 ], root ), new Position( [ 2 ], root ) ),
+			new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
 			null,
 			new Attribute( 'isNew', true ),
 			doc.version
@@ -62,7 +62,7 @@ describe( 'ChangeOperation', () => {
 
 		doc.applyOperation(
 			new ChangeOperation(
-				new Range( new Position( [ 0 ], root ), new Position( [ 2 ], root ) ),
+				new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
 				null,
 				newAttr,
 				doc.version
@@ -85,7 +85,7 @@ describe( 'ChangeOperation', () => {
 
 		doc.applyOperation(
 			new ChangeOperation(
-				new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
+				new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 				null,
 				newAttr,
 				doc.version
@@ -108,7 +108,7 @@ describe( 'ChangeOperation', () => {
 
 		doc.applyOperation(
 			new ChangeOperation(
-				new Range( new Position( [ 0 ], root ), new Position( [ 2 ], root ) ),
+				new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
 				oldAttr,
 				newAttr,
 				doc.version
@@ -135,7 +135,7 @@ describe( 'ChangeOperation', () => {
 
 		doc.applyOperation(
 			new ChangeOperation(
-				new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
+				new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 				x1Attr,
 				x2Attr,
 				doc.version
@@ -159,7 +159,7 @@ describe( 'ChangeOperation', () => {
 
 		doc.applyOperation(
 			new ChangeOperation(
-				new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
+				new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 				xAttr,
 				null,
 				doc.version
@@ -176,7 +176,7 @@ describe( 'ChangeOperation', () => {
 	it( 'should create a change operation as a reverse', () => {
 		let oldAttr = new Attribute( 'x', 'old' );
 		let newAttr = new Attribute( 'x', 'new' );
-		let range = new Range( new Position( [ 0 ], root ), new Position( [ 3 ], root ) );
+		let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) );
 		let operation = new ChangeOperation( range, oldAttr, newAttr, doc.version );
 		let reverse = operation.getReversed();
 
@@ -193,7 +193,7 @@ describe( 'ChangeOperation', () => {
 		root.insertChildren( 0, 'bar' );
 
 		let operation = new ChangeOperation(
-			new Range( new Position( [ 0 ], root ), new Position( [ 3 ], root ) ),
+			new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
 			null,
 			newAttr,
 			doc.version
@@ -218,7 +218,7 @@ describe( 'ChangeOperation', () => {
 		root.insertChildren( 0, new Text( 'bar', [ oldAttr ] ) );
 
 		let operation = new ChangeOperation(
-			new Range( new Position( [ 0 ], root ), new Position( [ 3 ], root ) ),
+			new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
 			oldAttr,
 			newAttr,
 			doc.version
@@ -246,7 +246,7 @@ describe( 'ChangeOperation', () => {
 		root.insertChildren( 0, new Text( 'bar', [ fooAttr ] ) );
 
 		let operation = new ChangeOperation(
-			new Range( new Position( [ 0 ], root ), new Position( [ 3 ], root ) ),
+			new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
 			fooAttr,
 			null,
 			doc.version
@@ -276,7 +276,7 @@ describe( 'ChangeOperation', () => {
 		expect( () => {
 			doc.applyOperation(
 				new ChangeOperation(
-					new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
+					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 					fooAttr,
 					null,
 					doc.version
@@ -294,7 +294,7 @@ describe( 'ChangeOperation', () => {
 		expect( () => {
 			doc.applyOperation(
 				new ChangeOperation(
-					new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
+					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 					null,
 					x2Attr,
 					doc.version
@@ -312,7 +312,7 @@ describe( 'ChangeOperation', () => {
 		expect( () => {
 			doc.applyOperation(
 				new ChangeOperation(
-					new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
+					new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
 					fooAttr,
 					barAttr,
 					doc.version
@@ -322,7 +322,7 @@ describe( 'ChangeOperation', () => {
 	} );
 
 	it( 'should create operation with the same parameters when cloned', () => {
-		let range = new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) );
+		let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
 		let oldAttr = new Attribute( 'foo', 'old' );
 		let newAttr = new Attribute( 'foo', 'bar' );
 		let baseVersion = doc.version;

+ 9 - 9
packages/ckeditor5-utils/tests/document/operation/insertoperation.js

@@ -41,7 +41,7 @@ describe( 'InsertOperation', () => {
 
 	it( 'should have proper type', () => {
 		const opp = new InsertOperation(
-			new Position( [ 0 ], root ),
+			new Position( root, [ 0 ] ),
 			new Character( 'x' ),
 			doc.version
 		);
@@ -52,7 +52,7 @@ describe( 'InsertOperation', () => {
 	it( 'should insert node', () => {
 		doc.applyOperation(
 			new InsertOperation(
-				new Position( [ 0 ], root ),
+				new Position( root, [ 0 ] ),
 				new Character( 'x' ),
 				doc.version
 			)
@@ -66,7 +66,7 @@ describe( 'InsertOperation', () => {
 	it( 'should insert set of nodes', () => {
 		doc.applyOperation(
 			new InsertOperation(
-				new Position( [ 0 ], root ),
+				new Position( root, [ 0 ] ),
 				'bar',
 				doc.version
 			)
@@ -84,7 +84,7 @@ describe( 'InsertOperation', () => {
 
 		doc.applyOperation(
 			new InsertOperation(
-				new Position( [ 1 ], root ),
+				new Position( root, [ 1 ] ),
 				'bar',
 				doc.version
 			)
@@ -102,7 +102,7 @@ describe( 'InsertOperation', () => {
 	it( 'should insert text', () => {
 		doc.applyOperation(
 			new InsertOperation(
-				new Position( [ 0 ], root ),
+				new Position( root, [ 0 ] ),
 				[ 'foo', new Character( 'x' ), 'bar' ],
 				doc.version
 			)
@@ -120,7 +120,7 @@ describe( 'InsertOperation', () => {
 	} );
 
 	it( 'should create a remove operation as a reverse', () => {
-		let position = new Position( [ 0 ], root );
+		let position = new Position( root, [ 0 ] );
 		let operation = new InsertOperation(
 			position,
 			[ 'foo', new Character( 'x' ), 'bar' ],
@@ -137,7 +137,7 @@ describe( 'InsertOperation', () => {
 
 	it( 'should undo insert node by applying reverse operation', () => {
 		let operation = new InsertOperation(
-			new Position( [ 0 ], root ),
+			new Position( root, [ 0 ] ),
 			new Character( 'x' ),
 			doc.version
 		);
@@ -156,7 +156,7 @@ describe( 'InsertOperation', () => {
 
 	it( 'should undo insert set of nodes by applying reverse operation', () => {
 		let operation = new InsertOperation(
-			new Position( [ 0 ], root ),
+			new Position( root, [ 0 ] ),
 			'bar',
 			doc.version
 		);
@@ -174,7 +174,7 @@ describe( 'InsertOperation', () => {
 	} );
 
 	it( 'should create operation with the same parameters when cloned', () => {
-		let position = new Position( [ 0 ], root );
+		let position = new Position( root, [ 0 ] );
 		let nodeA = new Node();
 		let nodeB = new Node();
 		let nodes = new NodeList( [ nodeA, nodeB ] );

+ 24 - 24
packages/ckeditor5-utils/tests/document/operation/moveoperation.js

@@ -38,8 +38,8 @@ describe( 'MoveOperation', () => {
 
 	it( 'should have proper type', () => {
 		const opp = new MoveOperation(
-			new Position( [ 0, 0 ], root ),
-			new Position( [ 1, 0 ], root ),
+			new Position( root, [ 0, 0 ] ),
+			new Position( root, [ 1, 0 ] ),
 			1,
 			doc.version
 		);
@@ -55,8 +55,8 @@ describe( 'MoveOperation', () => {
 
 		doc.applyOperation(
 			new MoveOperation(
-				new Position( [ 0, 0 ], root ),
-				new Position( [ 1, 0 ], root ),
+				new Position( root, [ 0, 0 ] ),
+				new Position( root, [ 1, 0 ] ),
 				1,
 				doc.version
 			)
@@ -76,8 +76,8 @@ describe( 'MoveOperation', () => {
 
 		doc.applyOperation(
 			new MoveOperation(
-				new Position( [ 2 ], root ),
-				new Position( [ 1 ], root ),
+				new Position( root, [ 2 ] ),
+				new Position( root, [ 1 ] ),
 				2,
 				doc.version
 			)
@@ -97,8 +97,8 @@ describe( 'MoveOperation', () => {
 
 		doc.applyOperation(
 			new MoveOperation(
-				new Position( [ 1 ], root ),
-				new Position( [ 4 ], root ),
+				new Position( root, [ 1 ] ),
+				new Position( root, [ 4 ] ),
 				2,
 				doc.version
 			)
@@ -116,8 +116,8 @@ describe( 'MoveOperation', () => {
 	it( 'should create a move operation as a reverse', () => {
 		let nodeList = new NodeList( 'bar' );
 
-		let sourcePosition = new Position( [ 0 ], root );
-		let targetPosition = new Position( [ 4 ], root );
+		let sourcePosition = new Position( root, [ 0 ] );
+		let targetPosition = new Position( root, [ 4 ] );
 
 		let operation = new MoveOperation( sourcePosition, targetPosition, nodeList.length, doc.version );
 
@@ -137,8 +137,8 @@ describe( 'MoveOperation', () => {
 		root.insertChildren( 0, [ p1, p2 ] );
 
 		let operation = new MoveOperation(
-			new Position( [ 0, 0 ], root ),
-			new Position( [ 1, 0 ], root ),
+			new Position( root, [ 0, 0 ] ),
+			new Position( root, [ 1, 0 ] ),
 			1,
 			doc.version
 		);
@@ -164,8 +164,8 @@ describe( 'MoveOperation', () => {
 		root.insertChildren( 0, 'xbarx' );
 
 		let operation = new MoveOperation(
-			new Position( [ 3 ], root ),
-			new Position( [ 1 ], root ),
+			new Position( root, [ 3 ] ),
+			new Position( root, [ 1 ] ),
 			3,
 			doc.version
 		);
@@ -179,8 +179,8 @@ describe( 'MoveOperation', () => {
 		root.insertChildren( 0, [ 'ab', p ] );
 
 		let operation = new MoveOperation(
-			new Position( [ 2, 0 ], root ),
-			new Position( [ 1 ], root ),
+			new Position( root, [ 2, 0 ] ),
+			new Position( root, [ 1 ] ),
 			3,
 			doc.version
 		);
@@ -194,8 +194,8 @@ describe( 'MoveOperation', () => {
 		root.insertChildren( 0, 'xbarx' );
 
 		let operation = new MoveOperation(
-			new Position( [ 1 ], root ),
-			new Position( [ 2 ], root ),
+			new Position( root, [ 1 ] ),
+			new Position( root, [ 2 ] ),
 			3,
 			doc.version
 		);
@@ -208,8 +208,8 @@ describe( 'MoveOperation', () => {
 		root.insertChildren( 0, [ 'ab', p, 'xy' ] );
 
 		let operation = new MoveOperation(
-			new Position( [ 1 ], root ),
-			new Position( [ 2, 0, 0 ], root ),
+			new Position( root, [ 1 ] ),
+			new Position( root, [ 2, 0, 0 ] ),
 			3,
 			doc.version
 		);
@@ -222,8 +222,8 @@ describe( 'MoveOperation', () => {
 		root.insertChildren( 0, [ 'ab', p, 'xy' ] );
 
 		let operation = new MoveOperation(
-			new Position( [ 1 ], root ),
-			new Position( [ 2, 0 ], root ),
+			new Position( root, [ 1 ] ),
+			new Position( root, [ 2, 0 ] ),
 			1,
 			doc.version
 		);
@@ -240,8 +240,8 @@ describe( 'MoveOperation', () => {
 	} );
 
 	it( 'should create operation with the same parameters when cloned', () => {
-		let sourcePosition = new Position( [ 0 ], root );
-		let targetPosition = new Position( [ 1 ], root );
+		let sourcePosition = new Position( root, [ 0 ] );
+		let targetPosition = new Position( root, [ 1 ] );
 		let howMany = 4;
 		let baseVersion = doc.version;
 

+ 2 - 2
packages/ckeditor5-utils/tests/document/operation/reinsertoperation.js

@@ -33,8 +33,8 @@ describe( 'ReinsertOperation', () => {
 		root = doc.createRoot( 'root' );
 		graveyard = doc._graveyard;
 
-		graveyardPosition = new Position( [ 0 ], graveyard );
-		rootPosition = new Position( [ 0 ], root );
+		graveyardPosition = new Position( graveyard, [ 0 ] );
+		rootPosition = new Position( root, [ 0 ] );
 
 		operation = new ReinsertOperation(
 			graveyardPosition,

+ 5 - 5
packages/ckeditor5-utils/tests/document/operation/removeoperation.js

@@ -36,7 +36,7 @@ describe( 'RemoveOperation', () => {
 
 	it( 'should have proper type', () => {
 		const opp = new RemoveOperation(
-			new Position( [ 2 ], root ),
+			new Position( root, [ 2 ] ),
 			2,
 			doc.version
 		);
@@ -46,7 +46,7 @@ describe( 'RemoveOperation', () => {
 
 	it( 'should extend MoveOperation class', () => {
 		let operation = new RemoveOperation(
-			new Position( [ 2 ], root ),
+			new Position( root, [ 2 ] ),
 			2,
 			doc.version
 		);
@@ -63,7 +63,7 @@ describe( 'RemoveOperation', () => {
 
 		doc.applyOperation(
 			new RemoveOperation(
-				new Position( [ 2 ], root ),
+				new Position( root, [ 2 ] ),
 				2,
 				doc.version
 			)
@@ -79,7 +79,7 @@ describe( 'RemoveOperation', () => {
 	} );
 
 	it( 'should create a reinsert operation as a reverse', () => {
-		let position = new Position( [ 0 ], root );
+		let position = new Position( root, [ 0 ] );
 		let operation = new RemoveOperation( position, 2, 0 );
 		let reverse = operation.getReversed();
 
@@ -91,7 +91,7 @@ describe( 'RemoveOperation', () => {
 	} );
 
 	it( 'should undo remove set of nodes by applying reverse operation', () => {
-		let position = new Position( [ 0 ], root );
+		let position = new Position( root, [ 0 ] );
 		let operation = new RemoveOperation( position, 3, 0 );
 		let reverse = operation.getReversed();
 

Diferenças do arquivo suprimidas por serem muito extensas
+ 202 - 202
packages/ckeditor5-utils/tests/document/operation/transform.js


+ 119 - 119
packages/ckeditor5-utils/tests/document/position.js

@@ -65,7 +65,7 @@ describe( 'position', () => {
 	} );
 
 	it( 'should create a position with path and document', () => {
-		let position = new Position( [ 0 ], root );
+		let position = new Position( root, [ 0 ] );
 
 		expect( position ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
 		expect( position ).to.have.property( 'root' ).that.equals( root );
@@ -73,21 +73,21 @@ describe( 'position', () => {
 
 	it( 'should throw error if given path is incorrect', () => {
 		expect( () => {
-			new Position( {}, root );
+			new Position( root, {} );
 		} ).to.throw( CKEditorError, /position-path-incorrect/ );
 
 		expect( () => {
-			new Position( [], root );
+			new Position( root, [] );
 		} ).to.throw( CKEditorError, /position-path-incorrect/ );
 	} );
 
 	it( 'should throw error if given root is not a RootElement instance', () => {
 		expect( () => {
-			new Position( [ 0 ] );
+			new Position();
 		} ).to.throw( CKEditorError, /position-root-not-rootelement/ );
 
 		expect( () => {
-			new Position( [ 0 ], new Element( 'p' ) );
+			new Position( new Element( 'p' ), [ 0 ] );
 		} ).to.throw( CKEditorError, /position-root-not-rootelement/ );
 	} );
 
@@ -157,41 +157,41 @@ describe( 'position', () => {
 	} );
 
 	it( 'should have parent', () => {
-		expect( new Position( [ 0 ], root ) ).to.have.property( 'parent' ).that.equals( root );
-		expect( new Position( [ 1 ], root ) ).to.have.property( 'parent' ).that.equals( root );
-		expect( new Position( [ 2 ], root ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( root, [ 0 ] ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( root, [ 1 ] ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( root, [ 2 ] ) ).to.have.property( 'parent' ).that.equals( root );
 
-		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'parent' ).that.equals( p );
+		expect( new Position( root, [ 0, 0 ] ) ).to.have.property( 'parent' ).that.equals( p );
 
-		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'parent' ).that.equals( ul );
-		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'parent' ).that.equals( ul );
-		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( root, [ 1, 0 ] ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( root, [ 1, 1 ] ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( root, [ 1, 2 ] ) ).to.have.property( 'parent' ).that.equals( ul );
 
-		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( root, [ 1, 0, 0 ] ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( root, [ 1, 0, 1 ] ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( root, [ 1, 0, 2 ] ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( root, [ 1, 0, 3 ] ) ).to.have.property( 'parent' ).that.equals( li1 );
 	} );
 
 	it( 'should have offset', () => {
-		expect( new Position( [ 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1 ], root ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 2 ], root ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( root, [ 0 ] ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( root, [ 1 ] ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( root, [ 2 ] ) ).to.have.property( 'offset' ).that.equals( 2 );
 
-		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( root, [ 0, 0 ] ) ).to.have.property( 'offset' ).that.equals( 0 );
 
-		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( root, [ 1, 0 ] ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( root, [ 1, 1 ] ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( root, [ 1, 2 ] ) ).to.have.property( 'offset' ).that.equals( 2 );
 
-		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'offset' ).that.equals( 2 );
-		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'offset' ).that.equals( 3 );
+		expect( new Position( root, [ 1, 0, 0 ] ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( root, [ 1, 0, 1 ] ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( root, [ 1, 0, 2 ] ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( root, [ 1, 0, 3 ] ) ).to.have.property( 'offset' ).that.equals( 3 );
 	} );
 
 	it( 'should be able to set offset', () => {
-		let position = new Position( [ 1, 0, 2 ], root );
+		let position = new Position( root, [ 1, 0, 2 ] );
 		position.offset = 4;
 
 		expect( position.offset ).to.equal( 4 );
@@ -199,47 +199,47 @@ describe( 'position', () => {
 	} );
 
 	it( 'should have nodeBefore', () => {
-		expect( new Position( [ 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( p );
-		expect( new Position( [ 2 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( ul );
+		expect( new Position( root, [ 0 ] ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( root, [ 1 ] ) ).to.have.property( 'nodeBefore' ).that.equals( p );
+		expect( new Position( root, [ 2 ] ) ).to.have.property( 'nodeBefore' ).that.equals( ul );
 
-		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( root, [ 0, 0 ] ) ).to.have.property( 'nodeBefore' ).that.is.null;
 
-		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( li1 );
-		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( li2 );
+		expect( new Position( root, [ 1, 0 ] ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( root, [ 1, 1 ] ) ).to.have.property( 'nodeBefore' ).that.equals( li1 );
+		expect( new Position( root, [ 1, 2 ] ) ).to.have.property( 'nodeBefore' ).that.equals( li2 );
 
-		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( f );
-		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( o );
-		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( z );
+		expect( new Position( root, [ 1, 0, 0 ] ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( root, [ 1, 0, 1 ] ) ).to.have.property( 'nodeBefore' ).that.equals( f );
+		expect( new Position( root, [ 1, 0, 2 ] ) ).to.have.property( 'nodeBefore' ).that.equals( o );
+		expect( new Position( root, [ 1, 0, 3 ] ) ).to.have.property( 'nodeBefore' ).that.equals( z );
 	} );
 
 	it( 'should have nodeAfter', () => {
-		expect( new Position( [ 0 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( p );
-		expect( new Position( [ 1 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( ul );
-		expect( new Position( [ 2 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( root, [ 0 ] ) ).to.have.property( 'nodeAfter' ).that.equals( p );
+		expect( new Position( root, [ 1 ] ) ).to.have.property( 'nodeAfter' ).that.equals( ul );
+		expect( new Position( root, [ 2 ] ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
-		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( root, [ 0, 0 ] ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
-		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( li1 );
-		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( li2 );
-		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( root, [ 1, 0 ] ) ).to.have.property( 'nodeAfter' ).that.equals( li1 );
+		expect( new Position( root, [ 1, 1 ] ) ).to.have.property( 'nodeAfter' ).that.equals( li2 );
+		expect( new Position( root, [ 1, 2 ] ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
-		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( f );
-		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( o );
-		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( z );
-		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( root, [ 1, 0, 0 ] ) ).to.have.property( 'nodeAfter' ).that.equals( f );
+		expect( new Position( root, [ 1, 0, 1 ] ) ).to.have.property( 'nodeAfter' ).that.equals( o );
+		expect( new Position( root, [ 1, 0, 2 ] ) ).to.have.property( 'nodeAfter' ).that.equals( z );
+		expect( new Position( root, [ 1, 0, 3 ] ) ).to.have.property( 'nodeAfter' ).that.is.null;
 	} );
 
 	it( 'should have proper parent path', () => {
-		let position = new Position( [ 1, 2, 3 ], root );
+		let position = new Position( root, [ 1, 2, 3 ] );
 
 		expect( position.getParentPath() ).to.deep.equal( [ 1, 2 ] );
 	} );
 
 	it( 'should return a new, equal position when cloned', () => {
-		const position = new Position( [ 1, 2, 3 ], root );
+		const position = new Position( root, [ 1, 2, 3 ] );
 		const clone = position.clone();
 
 		expect( clone ).not.to.be.equal( position ); // clone is not pointing to the same object as position
@@ -249,22 +249,22 @@ describe( 'position', () => {
 
 	describe( 'isBefore', () => {
 		it( 'should return true if given position has same root and is before this position', () => {
-			let position = new Position( [ 1, 1, 2 ], root );
-			let beforePosition = new Position( [ 1, 0 ], root );
+			let position = new Position( root, [ 1, 1, 2 ] );
+			let beforePosition = new Position( root, [ 1, 0 ] );
 
 			expect( position.isAfter( beforePosition ) ).to.be.true;
 		} );
 
 		it( 'should return false if given position has same root and is not before this position', () => {
-			let position = new Position( [ 1, 1, 2 ], root );
-			let afterPosition = new Position( [ 1, 2 ], root );
+			let position = new Position( root, [ 1, 1, 2 ] );
+			let afterPosition = new Position( root, [ 1, 2 ] );
 
 			expect( position.isAfter( afterPosition ) ).to.be.false;
 		} );
 
 		it( 'should return false if given position has different root', () => {
-			let position = new Position( [ 1, 1, 2 ], root );
-			let differentPosition = new Position( [ 1, 0 ], otherRoot );
+			let position = new Position( root, [ 1, 1, 2 ] );
+			let differentPosition = new Position( otherRoot, [ 1, 0 ] );
 
 			expect( position.isAfter( differentPosition ) ).to.be.false;
 		} );
@@ -272,22 +272,22 @@ describe( 'position', () => {
 
 	describe( 'isEqual', () => {
 		it( 'should return true if given position has same path and root', () => {
-			let position = new Position( [ 1, 1, 2 ], root );
-			let samePosition = new Position( [ 1, 1, 2 ], root );
+			let position = new Position( root, [ 1, 1, 2 ] );
+			let samePosition = new Position( root, [ 1, 1, 2 ] );
 
 			expect( position.isEqual( samePosition ) ).to.be.true;
 		} );
 
 		it( 'should return false if given position has different path', () => {
-			let position = new Position( [ 1, 1, 1 ], root );
-			let differentPosition = new Position( [ 1, 2, 2 ], root );
+			let position = new Position( root, [ 1, 1, 1 ] );
+			let differentPosition = new Position( root, [ 1, 2, 2 ] );
 
 			expect( position.isEqual( differentPosition ) ).to.be.false;
 		} );
 
 		it( 'should return false if given position has different root', () => {
-			let position = new Position( [ 1, 1, 1 ], root );
-			let differentPosition = new Position( [ 1, 1, 1 ], otherRoot );
+			let position = new Position( root, [ 1, 1, 1 ] );
+			let differentPosition = new Position( otherRoot, [ 1, 1, 1 ] );
 
 			expect( position.isEqual( differentPosition ) ).to.be.false;
 		} );
@@ -295,22 +295,22 @@ describe( 'position', () => {
 
 	describe( 'isAfter', () => {
 		it( 'should return true if given position has same root and is after this position', () => {
-			let position = new Position( [ 1, 1, 2 ], root );
-			let afterPosition = new Position( [ 1, 2 ], root );
+			let position = new Position( root, [ 1, 1, 2 ] );
+			let afterPosition = new Position( root, [ 1, 2 ] );
 
 			expect( position.isBefore( afterPosition ) ).to.be.true;
 		} );
 
 		it( 'should return false if given position has same root and is not after this position', () => {
-			let position = new Position( [ 1, 1, 2 ], root );
-			let beforePosition = new Position( [ 1, 0 ], root );
+			let position = new Position( root, [ 1, 1, 2 ] );
+			let beforePosition = new Position( root, [ 1, 0 ] );
 
 			expect( position.isBefore( beforePosition ) ).to.be.false;
 		} );
 
 		it( 'should return false if given position has different root', () => {
-			let position = new Position( [ 1, 1, 2 ], root );
-			let differentPosition = new Position( [ 1, 2 ], otherRoot );
+			let position = new Position( root, [ 1, 1, 2 ] );
+			let differentPosition = new Position( otherRoot, [ 1, 2 ] );
 
 			expect( position.isBefore( differentPosition ) ).to.be.false;
 		} );
@@ -318,29 +318,29 @@ describe( 'position', () => {
 
 	describe( 'compareWith', () => {
 		it( 'should return Position.SAME if positions are same', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const compared = new Position( [ 1, 2, 3 ], root );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const compared = new Position( root, [ 1, 2, 3 ] );
 
 			expect( position.compareWith( compared ) ).to.equal( Position.SAME );
 		} );
 
 		it( 'should return Position.BEFORE if the position is before compared one', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const compared = new Position( [ 1, 3 ], root );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const compared = new Position( root, [ 1, 3 ] );
 
 			expect( position.compareWith( compared ) ).to.equal( Position.BEFORE );
 		} );
 
 		it( 'should return Position.AFTER if the position is after compared one', () => {
-			const position = new Position( [ 1, 2, 3, 4 ], root );
-			const compared = new Position( [ 1, 2, 3 ], root );
+			const position = new Position( root, [ 1, 2, 3, 4 ] );
+			const compared = new Position( root, [ 1, 2, 3 ] );
 
 			expect( position.compareWith( compared ) ).to.equal( Position.AFTER );
 		} );
 
 		it( 'should return Position.DIFFERENT if positions are in different roots', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const compared = new Position( [ 1, 2, 3 ], otherRoot );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const compared = new Position( otherRoot, [ 1, 2, 3 ] );
 
 			expect( position.compareWith( compared ) ).to.equal( Position.DIFFERENT );
 		} );
@@ -348,58 +348,58 @@ describe( 'position', () => {
 
 	describe( 'getTransformedByInsertion', () => {
 		it( 'should return a new Position instance', () => {
-			const position = new Position( [ 0 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 2 ], root ), 4, false );
+			const position = new Position( root, [ 0 ] );
+			const transformed = position.getTransformedByInsertion( new Position( root, [ 2 ] ), 4, false );
 
 			expect( transformed ).not.to.equal( position );
 			expect( transformed ).to.be.instanceof( Position );
 		} );
 
 		it( 'should increment offset if insertion is in the same parent and closer offset', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 1, 2, 2 ], root ), 2, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByInsertion( new Position( root, [ 1, 2, 2 ] ), 2, false );
 
 			expect( transformed.offset ).to.equal( 5 );
 		} );
 
 		it( 'should not increment offset if insertion position is in different root', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 1, 2, 2 ], otherRoot ), 2, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByInsertion( new Position( otherRoot, [ 1, 2, 2 ] ), 2, false );
 
 			expect( transformed.offset ).to.equal( 3 );
 		} );
 
 		it( 'should not increment offset if insertion is in the same parent and the same offset', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 1, 2, 3 ], root ), 2, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByInsertion( new Position( root, [ 1, 2, 3 ] ), 2, false );
 
 			expect( transformed.offset ).to.equal( 3 );
 		} );
 
 		it( 'should increment offset if insertion is in the same parent and the same offset and it is inserted before', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 1, 2, 3 ], root ), 2, true );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByInsertion( new Position( root, [ 1, 2, 3 ] ), 2, true );
 
 			expect( transformed.offset ).to.equal( 5 );
 		} );
 
 		it( 'should not increment offset if insertion is in the same parent and further offset', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 1, 2, 4 ], root ), 2, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByInsertion( new Position( root, [ 1, 2, 4 ] ), 2, false );
 
 			expect( transformed.offset ).to.equal( 3 );
 		} );
 
 		it( 'should update path if insertion position parent is a node from that path and offset is before next node on that path', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 1, 2 ], root ), 2, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByInsertion( new Position( root, [ 1, 2 ] ), 2, false );
 
 			expect( transformed.path ).to.deep.equal( [ 1, 4, 3 ] );
 		} );
 
 		it( 'should not update path if insertion position parent is a node from that path and offset is after next node on that path', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByInsertion( new Position( [ 1, 3 ], root ), 2, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByInsertion( new Position( root, [ 1, 3 ] ), 2, false );
 
 			expect( transformed.path ).to.deep.equal( [ 1, 2, 3 ] );
 		} );
@@ -407,58 +407,58 @@ describe( 'position', () => {
 
 	describe( 'getTransformedByDeletion', () => {
 		it( 'should return a new Position instance', () => {
-			const position = new Position( [ 0 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 2 ], root ), 4 );
+			const position = new Position( root, [ 0 ] );
+			const transformed = position.getTransformedByDeletion( new Position( root, [ 2 ] ), 4 );
 
 			expect( transformed ).not.to.equal( position );
 			expect( transformed ).to.be.instanceof( Position );
 		} );
 
 		it( 'should return null if original position is inside one of removed nodes', () => {
-			const position = new Position( [ 1, 2 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 0 ], root ), 2 );
+			const position = new Position( root, [ 1, 2 ] );
+			const transformed = position.getTransformedByDeletion( new Position( root, [ 0 ] ), 2 );
 
 			expect( transformed ).to.be.null;
 		} );
 
 		it( 'should decrement offset if deletion is in the same parent and closer offset', () => {
-			const position = new Position( [ 1, 2, 7 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 1, 2, 2 ], root ), 2 );
+			const position = new Position( root, [ 1, 2, 7 ] );
+			const transformed = position.getTransformedByDeletion( new Position( root, [ 1, 2, 2 ] ), 2 );
 
 			expect( transformed.offset ).to.equal( 5 );
 		} );
 
 		it( 'should set position offset to deletion offset if position is between removed nodes', () => {
-			const position = new Position( [ 1, 2, 4 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 1, 2, 3 ], root ), 5 );
+			const position = new Position( root, [ 1, 2, 4 ] );
+			const transformed = position.getTransformedByDeletion( new Position( root, [ 1, 2, 3 ] ), 5 );
 
 			expect( transformed.offset ).to.equal( 3 );
 		} );
 
 		it( 'should not decrement offset if deletion position is in different root', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 1, 2, 1 ], otherRoot ), 2 );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByDeletion( new Position( otherRoot, [ 1, 2, 1 ] ), 2 );
 
 			expect( transformed.offset ).to.equal( 3 );
 		} );
 
 		it( 'should not decrement offset if deletion is in the same parent and further offset', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 1, 2, 4 ], root ), 2 );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByDeletion( new Position( root, [ 1, 2, 4 ] ), 2 );
 
 			expect( transformed.offset ).to.equal( 3 );
 		} );
 
 		it( 'should update path if deletion position parent is a node from that path and offset is before next node on that path', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 1, 0 ], root ), 2 );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByDeletion( new Position( root, [ 1, 0 ] ), 2 );
 
 			expect( transformed.path ).to.deep.equal( [ 1, 0, 3 ] );
 		} );
 
 		it( 'should not update path if deletion position parent is a node from that path and offset is after next node on that path', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByDeletion( new Position( [ 1, 3 ], root ), 2 );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByDeletion( new Position( root, [ 1, 3 ] ), 2 );
 
 			expect( transformed.path ).to.deep.equal( [ 1, 2, 3 ] );
 		} );
@@ -466,22 +466,22 @@ describe( 'position', () => {
 
 	describe( 'getTransformedByMove', () => {
 		it( 'should increment offset if a range was moved to the same parent and closer offset', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByMove( new Position( [ 2 ], root ), new Position( [ 1, 2, 0 ], root ), 3, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByMove( new Position( root, [ 2 ] ), new Position( root, [ 1, 2, 0 ] ), 3, false );
 
 			expect( transformed.path ).to.deep.equal( [ 1, 2, 6 ] );
 		} );
 
 		it( 'should decrement offset if a range was moved from the same parent and closer offset', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByMove( new Position( [ 1, 2, 0 ], root ), new Position( [ 2 ], root ), 3, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByMove( new Position( root, [ 1, 2, 0 ] ), new Position( root, [ 2 ] ), 3, false );
 
 			expect( transformed.path ).to.deep.equal( [ 1, 2, 0 ] );
 		} );
 
 		it( 'should update path if a range contained this position', () => {
-			const position = new Position( [ 1, 2, 3 ], root );
-			const transformed = position.getTransformedByMove( new Position( [ 1, 1 ], root ), new Position( [ 2, 1 ], root ), 3, false );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position.getTransformedByMove( new Position( root, [ 1, 1 ] ), new Position( root, [ 2, 1 ] ), 3, false );
 
 			expect( transformed.path ).to.deep.equal( [ 2, 2, 3 ] );
 		} );
@@ -489,9 +489,9 @@ describe( 'position', () => {
 
 	describe( '_getCombined', () => {
 		it( 'should return correct combination of this and given positions', () => {
-			const position = new Position( [ 1, 3, 4, 2 ], root );
-			const sourcePosition = new Position( [ 1, 1 ], root );
-			const targetPosition = new Position( [ 2, 5 ], root );
+			const position = new Position( root, [ 1, 3, 4, 2 ] );
+			const sourcePosition = new Position( root, [ 1, 1 ] );
+			const targetPosition = new Position( root, [ 2, 5 ] );
 
 			const combined = position._getCombined( sourcePosition, targetPosition );
 

+ 8 - 8
packages/ckeditor5-utils/tests/document/positioniterator.js

@@ -74,7 +74,7 @@ describe( 'range iterator', () => {
 	} );
 
 	it( 'should return next position', () => {
-		let iterator = new PositionIterator( new Position( [ 0 ], root ) ); // beginning of root
+		let iterator = new PositionIterator( new Position( root, [ 0 ] ) ); // beginning of root
 		let i, len;
 
 		for ( i = 0, len = expectedItems.length; i < len; i++ ) {
@@ -84,7 +84,7 @@ describe( 'range iterator', () => {
 	} );
 
 	it( 'should return previous position', () => {
-		let iterator = new PositionIterator( new Position( [ 2 ], root ) ); // ending of root
+		let iterator = new PositionIterator( new Position( root, [ 2 ] ) ); // ending of root
 
 		for ( let i = expectedItems.length - 1; i >= 0; i-- ) {
 			expect( iterator.previous() ).to.deep.equal( { done: false, value: expectedItems[ i ] } );
@@ -93,8 +93,8 @@ describe( 'range iterator', () => {
 	} );
 
 	it( 'should return next position in the boundaries', () => {
-		let start = new Position( [ 1, 0 ], root ); // p, 0
-		let end = new Position( [ 1, 3, 0 ], root ); // img, 0
+		let start = new Position( root, [ 1, 0 ] ); // p, 0
+		let end = new Position( root, [ 1, 3, 0 ] ); // img, 0
 
 		let iterator = new PositionIterator( new Range( start, end ) );
 
@@ -107,8 +107,8 @@ describe( 'range iterator', () => {
 	} );
 
 	it( 'should return previous position in the boundaries', () => {
-		let start = new Position( [ 1, 0 ], root ); // p, 0
-		let end = new Position( [ 1, 3, 0 ], root ); // img, 0
+		let start = new Position( root, [ 1, 0 ] ); // p, 0
+		let end = new Position( root, [ 1, 3, 0 ] ); // img, 0
 
 		let iterator = new PositionIterator( new Range( start, end ), end );
 
@@ -121,8 +121,8 @@ describe( 'range iterator', () => {
 	} );
 
 	it( 'should return iterate over the range', () => {
-		let start = new Position( [ 0 ], root ); // begging of root
-		let end = new Position( [ 2 ], root ); // ending of root
+		let start = new Position( root, [ 0 ] ); // begging of root
+		let end = new Position( root, [ 2 ] ); // ending of root
 		let range = new Range( start, end );
 
 		let i = 0;

+ 34 - 34
packages/ckeditor5-utils/tests/document/range.js

@@ -29,8 +29,8 @@ describe( 'Range', () => {
 		let doc = new Document();
 		root = doc.createRoot( 'root' );
 
-		start = new Position( [ 0 ], root );
-		end = new Position( [ 1 ], root );
+		start = new Position( root, [ 0 ] );
+		end = new Position( root, [ 1 ] );
 	} );
 
 	let range;
@@ -48,8 +48,8 @@ describe( 'Range', () => {
 
 	describe( 'isEqual', () => {
 		it( 'should return true if the ranges are the same', () => {
-			let sameStart = new Position( [ 0 ], root );
-			let sameEnd = new Position( [ 1 ], root );
+			let sameStart = new Position( root, [ 0 ] );
+			let sameEnd = new Position( root, [ 1 ] );
 
 			let sameRange = new Range( sameStart, sameEnd );
 
@@ -59,8 +59,8 @@ describe( 'Range', () => {
 		it( 'should return false if the start position is different', () => {
 			let range = new Range( start, end );
 
-			let diffStart = new Position( [ 1 ], root );
-			let sameEnd = new Position( [ 1 ], root );
+			let diffStart = new Position( root, [ 1 ] );
+			let sameEnd = new Position( root, [ 1 ] );
 
 			let diffRange = new Range( diffStart, sameEnd );
 
@@ -68,8 +68,8 @@ describe( 'Range', () => {
 		} );
 
 		it( 'should return false if the end position is different', () => {
-			let sameStart = new Position( [ 0 ], root );
-			let diffEnd = new Position( [ 0 ], root );
+			let sameStart = new Position( root, [ 0 ] );
+			let diffEnd = new Position( root, [ 0 ] );
 
 			let diffRange = new Range( sameStart, diffEnd );
 
@@ -119,7 +119,7 @@ describe( 'Range', () => {
 
 		describe( 'createFromPositionAndOffset', () => {
 			it( 'should make range from start position and offset', () => {
-				const position = new Position( [ 1, 2, 3 ], root );
+				const position = new Position( root, [ 1, 2, 3 ] );
 				const range = Range.createFromPositionAndOffset( position, 4 );
 
 				expect( range ).to.be.instanceof( Range );
@@ -141,23 +141,23 @@ describe( 'Range', () => {
 
 	describe( 'containsPosition', () => {
 		beforeEach( () => {
-			range = new Range( new Position( [ 1 ], root ), new Position( [ 3 ], root ) );
+			range = new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) );
 		} );
 
 		it( 'should return false if position is before range', () => {
-			const position = new Position( [ 0, 4 ], root );
+			const position = new Position( root, [ 0, 4 ] );
 
 			expect( range.containsPosition( position ) ).to.be.false;
 		} );
 
 		it( 'should return false if position is after range', () => {
-			const position = new Position( [ 3, 0 ], root );
+			const position = new Position( root, [ 3, 0 ] );
 
 			expect( range.containsPosition( position ) ).to.be.false;
 		} );
 
 		it( 'should return true if position is inside range', () => {
-			const position = new Position( [ 2, 2 ], root );
+			const position = new Position( root, [ 2, 2 ] );
 
 			expect( range.containsPosition( position ) ).to.be.true;
 		} );
@@ -165,32 +165,32 @@ describe( 'Range', () => {
 
 	describe( 'getTransformedByInsertion', () => {
 		it( 'should return an array of Range objects', () => {
-			const range = new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) );
-			const transformed = range.getTransformedByInsertion( new Position( [ 2 ], root ), 2 );
+			const range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
+			const transformed = range.getTransformedByInsertion( new Position( root, [ 2 ] ), 2 );
 
 			expect( transformed ).to.be.instanceof( Array );
 			expect( transformed[ 0 ] ).to.be.instanceof( Range );
 		} );
 
 		it( 'should update it\'s positions offsets if insertion is before range and they are affected', () => {
-			const range = new Range( new Position( [ 3, 2 ], root ), new Position( [ 3, 4 ], root ) );
-			const transformed = range.getTransformedByInsertion( new Position( [ 3, 1 ], root ), 2 );
+			const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 3, 4 ] ) );
+			const transformed = range.getTransformedByInsertion( new Position( root, [ 3, 1 ] ), 2 );
 
 			expect( transformed[ 0 ].start.offset ).to.equal( 4 );
 			expect( transformed[ 0 ].end.offset ).to.equal( 6 );
 		} );
 
 		it( 'should update it\'s positions paths if insertion is before range and they are affected', () => {
-			const range = new Range( new Position( [ 3, 2 ], root ), new Position( [ 4, 4 ], root ) );
-			const transformed = range.getTransformedByInsertion( new Position( [ 0 ], root ), 2 );
+			const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 4, 4 ] ) );
+			const transformed = range.getTransformedByInsertion( new Position( root, [ 0 ] ), 2 );
 
 			expect( transformed[ 0 ].start.path[ 0 ] ).to.equal( 5 );
 			expect( transformed[ 0 ].end.path[ 0 ] ).to.equal( 6 );
 		} );
 
 		it( 'should return array with two ranges and updated positions if insertion was in the middle of range', () => {
-			const range = new Range( new Position( [ 3, 2 ], root ), new Position( [ 5, 4 ], root ) );
-			const transformed = range.getTransformedByInsertion( new Position( [ 4, 1, 6 ], root ), 4 );
+			const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 5, 4 ] ) );
+			const transformed = range.getTransformedByInsertion( new Position( root, [ 4, 1, 6 ] ), 4 );
 
 			expect( transformed.length ).to.equal( 2 );
 
@@ -202,8 +202,8 @@ describe( 'Range', () => {
 		} );
 
 		it( 'should not updated positions if insertion is after range', () => {
-			const range = new Range( new Position( [ 3, 2 ], root ), new Position( [ 4, 4 ], root ) );
-			const transformed = range.getTransformedByInsertion( new Position( [ 4, 4 ], root ), 3 );
+			const range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 4, 4 ] ) );
+			const transformed = range.getTransformedByInsertion( new Position( root, [ 4, 4 ] ), 3 );
 
 			expect( transformed[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
 			expect( transformed[ 0 ].end.path ).to.deep.equal( [ 4, 4 ] );
@@ -214,11 +214,11 @@ describe( 'Range', () => {
 		let range;
 
 		beforeEach( () => {
-			range = new Range( new Position( [ 3, 2 ], root ), new Position( [ 5, 4 ], root ) );
+			range = new Range( new Position( root, [ 3, 2 ] ), new Position( root, [ 5, 4 ] ) );
 		} );
 
 		it( 'should return an array of Range objects', () => {
-			const otherRange = new Range( new Position( [ 6 ], root ), new Position( [ 7 ], root ) );
+			const otherRange = new Range( new Position( root, [ 6 ] ), new Position( root, [ 7 ] ) );
 			const diff = range.getDifference( otherRange );
 
 			expect( diff ).to.be.instanceof( Array );
@@ -226,7 +226,7 @@ describe( 'Range', () => {
 		} );
 
 		it( 'should return original range if other range does not intersect with it', () => {
-			const otherRange = new Range( new Position( [ 6 ], root ), new Position( [ 7 ], root ) );
+			const otherRange = new Range( new Position( root, [ 6 ] ), new Position( root, [ 7 ] ) );
 			const diff = range.getDifference( otherRange );
 
 			expect( diff[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
@@ -234,7 +234,7 @@ describe( 'Range', () => {
 		} );
 
 		it( 'should return shrunken range if other range intersects with it', () => {
-			const otherRange = new Range( new Position( [ 4, 1 ], root ), new Position( [ 7 ], root ) );
+			const otherRange = new Range( new Position( root, [ 4, 1 ] ), new Position( root, [ 7 ] ) );
 			const diff = range.getDifference( otherRange );
 
 			expect( diff[ 0 ].start.path ).to.deep.equal( [ 3, 2 ] );
@@ -242,14 +242,14 @@ describe( 'Range', () => {
 		} );
 
 		it( 'should return an empty array if other range contains or is same as the original range', () => {
-			const otherRange = new Range( new Position( [ 2 ], root ), new Position( [ 6 ], root ) );
+			const otherRange = new Range( new Position( root, [ 2 ] ), new Position( root, [ 6 ] ) );
 			const diff = range.getDifference( otherRange );
 
 			expect( diff.length ).to.equal( 0 );
 		} );
 
 		it( 'should two ranges if other range is contained by the original range', () => {
-			const otherRange = new Range( new Position( [ 3, 7 ], root ), new Position( [ 4, 1 ], root ) );
+			const otherRange = new Range( new Position( root, [ 3, 7 ] ), new Position( root, [ 4, 1 ] ) );
 			const diff = range.getDifference( otherRange );
 
 			expect( diff.length ).to.equal( 2 );
@@ -266,32 +266,32 @@ describe( 'Range', () => {
 		let range;
 
 		beforeEach( () => {
-			range = new Range( new Position( [ 3, 2 ], root ), new Position( [ 5, 4 ], root ) );
+			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( [ 5, 4 ], root ), new Position( [ 7 ], root ) );
+			const otherRange = new Range( new Position( root, [ 5, 4 ] ), new Position( root, [ 7 ] ) );
 			const common = range.getIntersection( otherRange );
 
 			expect( common ).to.be.null;
 		} );
 
 		it( 'should return a range equal to the common part of ranges - original range contains the other range', () => {
-			const otherRange = new Range( new Position( [ 4 ], root ), new Position( [ 5 ], root ) );
+			const otherRange = new Range( new Position( root, [ 4 ] ), new Position( root, [ 5 ] ) );
 			const common = range.getIntersection( otherRange );
 
 			expect( common.isEqual( otherRange ) ).to.be.true;
 		} );
 
 		it( 'should return a range equal to the common part of ranges - original range is contained by the other range', () => {
-			const otherRange = new Range( new Position( [ 3 ], root ), new Position( [ 6 ], root ) );
+			const otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 6 ] ) );
 			const common = range.getIntersection( otherRange );
 
 			expect( common.isEqual( range ) ).to.be.true;
 		} );
 
 		it( 'should return a range equal to the common part of ranges - original range intersects with the other range', () => {
-			const otherRange = new Range( new Position( [ 3 ], root ), new Position( [ 4, 7 ], root ) );
+			const otherRange = new Range( new Position( root, [ 3 ] ), new Position( root, [ 4, 7 ] ) );
 			const common = range.getIntersection( otherRange );
 
 			expect( common.start.path ).to.deep.equal( [ 3, 2 ] );