ソースを参照

Position use root + path instead of doc + path.

Piotr Jasiun 10 年 前
コミット
de701d6838

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

@@ -19,7 +19,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		 * @param {Array} path Position path. See {@link #path} property for more information.
 		 * @param {document.Document} doc Document which position refers to.
 		 */
-		constructor( path, doc ) {
+		constructor( path, root ) {
 			/**
 			 * Position of the node it the tree. For example:
 			 *
@@ -44,7 +44,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 			 *
 			 * @type {document.Document}
 			 */
-			this.doc = doc;
+			this.root = root;
 		}
 
 		/**
@@ -54,12 +54,12 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		 * @param {Number} offset Position offset.
 		 * @param {document.Document} doc Document which position refers to.
 		 */
-		static makePositionFromParentAndOffset( parent, offset, doc ) {
+		static makePositionFromParentAndOffset( parent, offset, root ) {
 			var path = parent.getPath();
 
 			path.push( offset );
 
-			return new Position( path, doc );
+			return new Position( path, root );
 		}
 
 		/**
@@ -68,7 +68,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		 * @param {document.node} node Node the position should be directly before.
 		 * @param {document.Document} doc Document which position refers to.
 		 */
-		static makePositionBefore( node, doc ) {
+		static makePositionBefore( node, root ) {
 			if ( !node.parent ) {
 				/**
 				 * You can not make position before root.
@@ -79,7 +79,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 				throw new CKEditorError( 'position-before-root: You can not make position before root.', { root: node } );
 			}
 
-			return Position.makePositionFromParentAndOffset( node.parent, node.positionInParent, doc );
+			return Position.makePositionFromParentAndOffset( node.parent, node.positionInParent, root );
 		}
 
 		/**
@@ -88,7 +88,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		 * @param {document.node} node Node the position should be directly after.
 		 * @param {document.Document} doc Document which position refers to.
 		 */
-		static makePositionAfter( node, doc ) {
+		static makePositionAfter( node, root ) {
 			if ( !node.parent ) {
 				/**
 				 * You can not make position after root.
@@ -99,7 +99,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 				throw new CKEditorError( 'position-after-root: You can not make position after root.', { root: node } );
 			}
 
-			return Position.makePositionFromParentAndOffset( node.parent, node.positionInParent + 1, doc );
+			return Position.makePositionFromParentAndOffset( node.parent, node.positionInParent + 1, root );
 		}
 
 		/**
@@ -109,7 +109,7 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		 * @property {document.Element} parent
 		 */
 		get parent() {
-			var parent = this.doc.root;
+			var parent = this.root;
 
 			var i, len;
 

+ 6 - 6
packages/ckeditor5-utils/src/document/positioniterator.js

@@ -75,15 +75,15 @@ CKEDITOR.define( [
 			var nodeAfter = position.nodeAfter;
 
 			if ( nodeAfter instanceof Element ) {
-				this.position = Position.makePositionFromParentAndOffset( nodeAfter, 0, position.doc );
+				this.position = Position.makePositionFromParentAndOffset( nodeAfter, 0, position.root );
 
 				return formatReturnValue( OPENING_TAG, nodeAfter );
 			} else if ( nodeAfter instanceof Character ) {
-				this.position = Position.makePositionFromParentAndOffset( parent, position.offset + 1, position.doc );
+				this.position = Position.makePositionFromParentAndOffset( parent, position.offset + 1, position.root );
 
 				return formatReturnValue( CHARACTER, nodeAfter );
 			} else {
-				this.position = Position.makePositionFromParentAndOffset( parent.parent, parent.positionInParent + 1, position.doc );
+				this.position = Position.makePositionFromParentAndOffset( parent.parent, parent.positionInParent + 1, position.root );
 
 				return formatReturnValue( CLOSING_TAG, this.position.nodeBefore );
 			}
@@ -115,15 +115,15 @@ CKEDITOR.define( [
 			var nodeBefore = position.nodeBefore;
 
 			if ( nodeBefore instanceof Element ) {
-				this.position = Position.makePositionFromParentAndOffset( nodeBefore, nodeBefore.children.length, position.doc );
+				this.position = Position.makePositionFromParentAndOffset( nodeBefore, nodeBefore.children.length, position.root );
 
 				return formatReturnValue( CLOSING_TAG, nodeBefore );
 			} else if ( nodeBefore instanceof Character ) {
-				this.position = Position.makePositionFromParentAndOffset( parent, position.offset - 1, position.doc );
+				this.position = Position.makePositionFromParentAndOffset( parent, position.offset - 1, position.root );
 
 				return formatReturnValue( CHARACTER, nodeBefore );
 			} else {
-				this.position = Position.makePositionFromParentAndOffset( parent.parent, parent.positionInParent, position.doc );
+				this.position = Position.makePositionFromParentAndOffset( parent.parent, parent.positionInParent, position.root );
 
 				return formatReturnValue( OPENING_TAG, this.position.nodeAfter );
 			}

+ 19 - 19
packages/ckeditor5-utils/tests/document/changeoperation.js

@@ -34,7 +34,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'r' ) );
 
 		doc.applyOperation( new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 2 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 2 ], doc.root ) ),
 			null,
 			newAttr,
 			doc.version ) );
@@ -64,8 +64,8 @@ describe( 'ChangeOperation', function() {
 
 		doc.applyOperation( new ChangeOperation(
 			[
-				new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
-				new Range( new Position( [ 2 ], doc ), new Position( [ 3 ], doc ) )
+				new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
+				new Range( new Position( [ 2 ], doc.root ), new Position( [ 3 ], doc.root ) )
 			],
 			null,
 			newAttr,
@@ -95,7 +95,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'x', [ fooAttr, barAttr ] ) );
 
 		doc.applyOperation( new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
 			null,
 			newAttr,
 			doc.version ) );
@@ -127,8 +127,8 @@ describe( 'ChangeOperation', function() {
 
 		doc.applyOperation( new ChangeOperation(
 			[
-				new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
-				new Range( new Position( [ 2 ], doc ), new Position( [ 3 ], doc ) )
+				new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
+				new Range( new Position( [ 2 ], doc.root ), new Position( [ 3 ], doc.root ) )
 			],
 			oldAttr,
 			newAttr,
@@ -162,7 +162,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'r', [ oldAttr ] ) );
 
 		doc.applyOperation( new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 2 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 2 ], doc.root ) ),
 			oldAttr,
 			newAttr,
 			doc.version ) );
@@ -195,7 +195,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'x', [ fooAttr, x1Attr, barAttr ] ) );
 
 		doc.applyOperation( new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
 			x1Attr,
 			x2Attr,
 			doc.version ) );
@@ -225,7 +225,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'x', [ fooAttr, xAttr, barAttr ] ) );
 
 		doc.applyOperation( new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
 			xAttr,
 			null,
 			doc.version ) );
@@ -255,8 +255,8 @@ describe( 'ChangeOperation', function() {
 
 		doc.applyOperation( new ChangeOperation(
 			[
-				new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
-				new Range( new Position( [ 2 ], doc ), new Position( [ 3 ], doc ) )
+				new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
+				new Range( new Position( [ 2 ], doc.root ), new Position( [ 3 ], doc.root ) )
 			],
 			fooAttr,
 			null,
@@ -281,7 +281,7 @@ describe( 'ChangeOperation', function() {
 		var oldAttr = new Attribute( 'x', 'old' );
 		var newAttr = new Attribute( 'x', 'new' );
 
-		var ranges = [ new Range( new Position( [ 0 ], doc ), new Position( [ 3 ], doc ) ) ];
+		var ranges = [ new Range( new Position( [ 0 ], doc.root ), new Position( [ 3 ], doc.root ) ) ];
 
 		var oppertaion = new ChangeOperation( ranges, oldAttr, newAttr, doc.version );
 
@@ -311,7 +311,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'r' ) );
 
 		var oppertaion = new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 3 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 3 ], doc.root ) ),
 			null,
 			newAttr,
 			doc.version );
@@ -347,7 +347,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'r', [ oldAttr ] ) );
 
 		var oppertaion = new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 3 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 3 ], doc.root ) ),
 			oldAttr,
 			newAttr,
 			doc.version );
@@ -385,7 +385,7 @@ describe( 'ChangeOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'r', [ fooAttr ] ) );
 
 		var oppertaion = new ChangeOperation(
-			new Range( new Position( [ 0 ], doc ), new Position( [ 3 ], doc ) ),
+			new Range( new Position( [ 0 ], doc.root ), new Position( [ 3 ], doc.root ) ),
 			fooAttr,
 			null,
 			doc.version );
@@ -423,7 +423,7 @@ describe( 'ChangeOperation', function() {
 
 		expect( function() {
 			doc.applyOperation( new ChangeOperation(
-				new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
+				new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
 				fooAttr,
 				null,
 				doc.version ) );
@@ -448,7 +448,7 @@ describe( 'ChangeOperation', function() {
 
 		expect( function() {
 			doc.applyOperation( new ChangeOperation(
-				new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
+				new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
 				null,
 				x2Attr,
 				doc.version ) );
@@ -473,7 +473,7 @@ describe( 'ChangeOperation', function() {
 
 		expect( function() {
 			doc.applyOperation( new ChangeOperation(
-				new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
+				new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
 				fooAttr,
 				barAttr,
 				doc.version ) );
@@ -498,7 +498,7 @@ describe( 'ChangeOperation', function() {
 
 		expect( function() {
 			doc.applyOperation( new ChangeOperation(
-				new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
+				new Range( new Position( [ 0 ], doc.root ), new Position( [ 1 ], doc.root ) ),
 				x1Attr,
 				x2Attr,
 				doc.version ) );

+ 7 - 7
packages/ckeditor5-utils/tests/document/insertoperation.js

@@ -24,7 +24,7 @@ describe( 'InsertOperation', function() {
 		var doc = new Document();
 
 		doc.applyOperation( new InsertOperation(
-			new Position( [ 0 ], doc ),
+			new Position( [ 0 ], doc.root ),
 			new Character( null, 'x' ),
 			doc.version ) );
 
@@ -42,7 +42,7 @@ describe( 'InsertOperation', function() {
 		var doc = new Document();
 
 		doc.applyOperation( new InsertOperation(
-			new Position( [ 0 ], doc ),
+			new Position( [ 0 ], doc.root ),
 			[ new Character( null, 'b' ), new Character( null, 'a' ), new Character( null, 'r' ) ],
 			doc.version ) );
 
@@ -65,7 +65,7 @@ describe( 'InsertOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'y' ) );
 
 		doc.applyOperation( new InsertOperation(
-			new Position( [ 1 ], doc ),
+			new Position( [ 1 ], doc.root ),
 			[ new Character( null, 'b' ), new Character( null, 'a' ), new Character( null, 'r' ) ],
 			doc.version ) );
 
@@ -87,7 +87,7 @@ describe( 'InsertOperation', function() {
 		var doc = new Document();
 
 		doc.applyOperation( new InsertOperation(
-			new Position( [ 0 ], doc ),
+			new Position( [ 0 ], doc.root ),
 			[ 'foo', new Character( null, 'x' ), 'bar' ],
 			doc.version ) );
 
@@ -112,7 +112,7 @@ describe( 'InsertOperation', function() {
 		var doc = new Document();
 
 		var nodes = [ new Character( null, 'b' ), new Character( null, 'a' ), new Character( null, 'r' ) ];
-		var position = new Position( [ 0 ], doc );
+		var position = new Position( [ 0 ], doc.root );
 
 		var operation = new InsertOperation( position, nodes, 0 );
 
@@ -133,7 +133,7 @@ describe( 'InsertOperation', function() {
 		var doc = new Document();
 
 		var operation = new InsertOperation(
-			new Position( [ 0 ], doc ),
+			new Position( [ 0 ], doc.root ),
 			new Character( null, 'x' ),
 			doc.version );
 
@@ -158,7 +158,7 @@ describe( 'InsertOperation', function() {
 		var doc = new Document();
 
 		var operation = new InsertOperation(
-			new Position( [ 0 ], doc ),
+			new Position( [ 0 ], doc.root ),
 			[ new Character( null, 'b' ), new Character( null, 'a' ), new Character( null, 'r' ) ],
 			doc.version );
 

+ 10 - 10
packages/ckeditor5-utils/tests/document/moveoperation.js

@@ -32,8 +32,8 @@ describe( 'MoveOperation', function() {
 		p1.children.push( new Element( doc.p1, 'x' ) );
 
 		doc.applyOperation( new MoveOperation(
-			new Position( [ 0, 0 ], doc ),
-			new Position( [ 1, 0 ], doc ),
+			new Position( [ 0, 0 ], doc.root ),
+			new Position( [ 1, 0 ], doc.root ),
 			p1.children[ 0 ],
 			doc.version ) );
 
@@ -61,8 +61,8 @@ describe( 'MoveOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'x' ) );
 
 		doc.applyOperation( new MoveOperation(
-			new Position( [ 2 ], doc ),
-			new Position( [ 1 ], doc ),
+			new Position( [ 2 ], doc.root ),
+			new Position( [ 1 ], doc.root ),
 			[ doc.root.children[ 2 ],  doc.root.children[ 3 ] ],
 			doc.version ) );
 
@@ -90,8 +90,8 @@ describe( 'MoveOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'x' ) );
 
 		doc.applyOperation( new MoveOperation(
-			new Position( [ 1 ], doc ),
-			new Position( [ 4 ], doc ),
+			new Position( [ 1 ], doc.root ),
+			new Position( [ 4 ], doc.root ),
 			[ doc.root.children[ 1 ],  doc.root.children[ 2 ] ],
 			doc.version ) );
 
@@ -114,8 +114,8 @@ describe( 'MoveOperation', function() {
 
 		var nodes = [ new Character( doc.root, 'b' ), new Character( doc.root, 'a' ), new Character( doc.root, 'r' ) ];
 
-		var sourcePosition = new Position( [ 0 ], doc );
-		var targetPosition = new Position( [ 4 ], doc );
+		var sourcePosition = new Position( [ 0 ], doc.root );
+		var targetPosition = new Position( [ 4 ], doc.root );
 
 		var operation = new MoveOperation( sourcePosition, targetPosition, nodes, doc.version );
 
@@ -145,8 +145,8 @@ describe( 'MoveOperation', function() {
 		p1.children.push( new Element( doc.p1, 'x' ) );
 
 		var operation =  new MoveOperation(
-			new Position( [ 0, 0 ], doc ),
-			new Position( [ 1, 0 ], doc ),
+			new Position( [ 0, 0 ], doc.root ),
+			new Position( [ 1, 0 ], doc.root ),
 			p1.children[ 0 ],
 			doc.version );
 

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

@@ -73,49 +73,49 @@ describe( 'position', function() {
 	it( 'should create a position with path and document', function() {
 		var Position = modules[ 'document/position' ];
 
-		var position = new Position( [ 0 ], doc );
+		var position = new Position( [ 0 ], doc.root );
 
 		expect( position ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
-		expect( position ).to.have.property( 'doc' ).that.equals( doc );
+		expect( position ).to.have.property( 'root' ).that.equals( doc.root );
 	} );
 
 	it( 'should make positions form node and offset', function() {
 		var Position = modules[ 'document/position' ];
 
-		expect( Position.makePositionFromParentAndOffset( root, 0, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
-		expect( Position.makePositionFromParentAndOffset( root, 1, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
-		expect( Position.makePositionFromParentAndOffset( root, 2, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
+		expect( Position.makePositionFromParentAndOffset( root, 0, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
+		expect( Position.makePositionFromParentAndOffset( root, 1, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
+		expect( Position.makePositionFromParentAndOffset( root, 2, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
 
-		expect( Position.makePositionFromParentAndOffset( p, 0, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 0, 0 ] );
+		expect( Position.makePositionFromParentAndOffset( p, 0, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 0, 0 ] );
 
-		expect( Position.makePositionFromParentAndOffset( ul, 0, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0 ] );
-		expect( Position.makePositionFromParentAndOffset( ul, 1, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1 ] );
-		expect( Position.makePositionFromParentAndOffset( ul, 2, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 2 ] );
+		expect( Position.makePositionFromParentAndOffset( ul, 0, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0 ] );
+		expect( Position.makePositionFromParentAndOffset( ul, 1, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1 ] );
+		expect( Position.makePositionFromParentAndOffset( ul, 2, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 2 ] );
 
-		expect( Position.makePositionFromParentAndOffset( li1, 0, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 0 ] );
-		expect( Position.makePositionFromParentAndOffset( li1, 1, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 1 ] );
-		expect( Position.makePositionFromParentAndOffset( li1, 2, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 2 ] );
-		expect( Position.makePositionFromParentAndOffset( li1, 3, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 3 ] );
+		expect( Position.makePositionFromParentAndOffset( li1, 0, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 0 ] );
+		expect( Position.makePositionFromParentAndOffset( li1, 1, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 1 ] );
+		expect( Position.makePositionFromParentAndOffset( li1, 2, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 2 ] );
+		expect( Position.makePositionFromParentAndOffset( li1, 3, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 3 ] );
 	} );
 
 	it( 'should make positions before elements', function() {
 		var Position = modules[ 'document/position' ];
 
-		expect( Position.makePositionBefore( p, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
+		expect( Position.makePositionBefore( p, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
 
-		expect( Position.makePositionBefore( ul, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
+		expect( Position.makePositionBefore( ul, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
 
-		expect( Position.makePositionBefore( li1, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0 ] );
+		expect( Position.makePositionBefore( li1, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0 ] );
 
-		expect( Position.makePositionBefore( f, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 0 ] );
-		expect( Position.makePositionBefore( o, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 1 ] );
-		expect( Position.makePositionBefore( z, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 2 ] );
+		expect( Position.makePositionBefore( f, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 0 ] );
+		expect( Position.makePositionBefore( o, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 1 ] );
+		expect( Position.makePositionBefore( z, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 2 ] );
 
-		expect( Position.makePositionBefore( li2, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1 ] );
+		expect( Position.makePositionBefore( li2, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1 ] );
 
-		expect( Position.makePositionBefore( b, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 0 ] );
-		expect( Position.makePositionBefore( a, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 1 ] );
-		expect( Position.makePositionBefore( r, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 2 ] );
+		expect( Position.makePositionBefore( b, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 0 ] );
+		expect( Position.makePositionBefore( a, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 1 ] );
+		expect( Position.makePositionBefore( r, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 2 ] );
 	} );
 
 	it( 'should throw error if one try to make positions before root', function() {
@@ -123,28 +123,28 @@ describe( 'position', function() {
 		var CKEditorError = modules.ckeditorerror;
 
 		expect( function() {
-			Position.makePositionBefore( root, doc );
+			Position.makePositionBefore( root, doc.root );
 		} ).to.throw( CKEditorError, /position-before-root/ );
 	} );
 
 	it( 'should make positions after elements', function() {
 		var Position = modules[ 'document/position' ];
 
-		expect( Position.makePositionAfter( p, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
+		expect( Position.makePositionAfter( p, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
 
-		expect( Position.makePositionAfter( ul, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
+		expect( Position.makePositionAfter( ul, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
 
-		expect( Position.makePositionAfter( li1, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1 ] );
+		expect( Position.makePositionAfter( li1, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1 ] );
 
-		expect( Position.makePositionAfter( f, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 1 ] );
-		expect( Position.makePositionAfter( o, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 2 ] );
-		expect( Position.makePositionAfter( z, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 3 ] );
+		expect( Position.makePositionAfter( f, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 1 ] );
+		expect( Position.makePositionAfter( o, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 2 ] );
+		expect( Position.makePositionAfter( z, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0, 3 ] );
 
-		expect( Position.makePositionAfter( li2, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 2 ] );
+		expect( Position.makePositionAfter( li2, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 2 ] );
 
-		expect( Position.makePositionAfter( b, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 1 ] );
-		expect( Position.makePositionAfter( a, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 2 ] );
-		expect( Position.makePositionAfter( r, doc ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 3 ] );
+		expect( Position.makePositionAfter( b, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 1 ] );
+		expect( Position.makePositionAfter( a, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 2 ] );
+		expect( Position.makePositionAfter( r, doc.root ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 1, 3 ] );
 	} );
 
 	it( 'should throw error if one try to make positions after root', function() {
@@ -152,91 +152,91 @@ describe( 'position', function() {
 		var CKEditorError = modules.ckeditorerror;
 
 		expect( function() {
-			Position.makePositionAfter( root, doc );
+			Position.makePositionAfter( root, doc.root );
 		} ).to.throw( CKEditorError, /position-after-root/ );
 	} );
 
 	it( 'should have parent', function() {
 		var Position = modules[ 'document/position' ];
 
-		expect( new Position( [ 0 ], doc ) ).to.have.property( 'parent' ).that.equals( root );
-		expect( new Position( [ 1 ], doc ) ).to.have.property( 'parent' ).that.equals( root );
-		expect( new Position( [ 2 ], doc ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'parent' ).that.equals( root );
 
-		expect( new Position( [ 0, 0 ], doc ) ).to.have.property( 'parent' ).that.equals( p );
+		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( p );
 
-		expect( new Position( [ 1, 0 ], doc ) ).to.have.property( 'parent' ).that.equals( ul );
-		expect( new Position( [ 1, 1 ], doc ) ).to.have.property( 'parent' ).that.equals( ul );
-		expect( new Position( [ 1, 2 ], doc ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'parent' ).that.equals( ul );
 
-		expect( new Position( [ 1, 0, 0 ], doc ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 1 ], doc ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 2 ], doc ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 3 ], doc ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
 	} );
 
 	it( 'should have offset', function() {
 		var Position = modules[ 'document/position' ];
 
-		expect( new Position( [ 0 ], doc ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1 ], doc ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 2 ], doc ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 2 );
 
-		expect( new Position( [ 0, 0 ], doc ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
 
-		expect( new Position( [ 1, 0 ], doc ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1, 1 ], doc ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 1, 2 ], doc ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 2 );
 
-		expect( new Position( [ 1, 0, 0 ], doc ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1, 0, 1 ], doc ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 1, 0, 2 ], doc ) ).to.have.property( 'offset' ).that.equals( 2 );
-		expect( new Position( [ 1, 0, 3 ], doc ) ).to.have.property( 'offset' ).that.equals( 3 );
+		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 3 );
 	} );
 
 	it( 'should have nodeBefore', function() {
 		var Position = modules[ 'document/position' ];
 
-		expect( new Position( [ 0 ], doc ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1 ], doc ) ).to.have.property( 'nodeBefore' ).that.equals( p );
-		expect( new Position( [ 2 ], doc ) ).to.have.property( 'nodeBefore' ).that.equals( ul );
+		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( p );
+		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( ul );
 
-		expect( new Position( [ 0, 0 ], doc ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
 
-		expect( new Position( [ 1, 0 ], doc ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1, 1 ], doc ) ).to.have.property( 'nodeBefore' ).that.equals( li1 );
-		expect( new Position( [ 1, 2 ], doc ) ).to.have.property( 'nodeBefore' ).that.equals( li2 );
+		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( li1 );
+		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( li2 );
 
-		expect( new Position( [ 1, 0, 0 ], doc ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1, 0, 1 ], doc ) ).to.have.property( 'nodeBefore' ).that.equals( f );
-		expect( new Position( [ 1, 0, 2 ], doc ) ).to.have.property( 'nodeBefore' ).that.equals( o );
-		expect( new Position( [ 1, 0, 3 ], doc ) ).to.have.property( 'nodeBefore' ).that.equals( z );
+		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( f );
+		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( o );
+		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( z );
 	} );
 
 	it( 'should have nodeAfter', function() {
 		var Position = modules[ 'document/position' ];
 
-		expect( new Position( [ 0 ], doc ) ).to.have.property( 'nodeAfter' ).that.equals( p );
-		expect( new Position( [ 1 ], doc ) ).to.have.property( 'nodeAfter' ).that.equals( ul );
-		expect( new Position( [ 2 ], doc ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( p );
+		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( ul );
+		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
-		expect( new Position( [ 0, 0 ], doc ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
-		expect( new Position( [ 1, 0 ], doc ) ).to.have.property( 'nodeAfter' ).that.equals( li1 );
-		expect( new Position( [ 1, 1 ], doc ) ).to.have.property( 'nodeAfter' ).that.equals( li2 );
-		expect( new Position( [ 1, 2 ], doc ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( li1 );
+		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( li2 );
+		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
-		expect( new Position( [ 1, 0, 0 ], doc ) ).to.have.property( 'nodeAfter' ).that.equals( f );
-		expect( new Position( [ 1, 0, 1 ], doc ) ).to.have.property( 'nodeAfter' ).that.equals( o );
-		expect( new Position( [ 1, 0, 2 ], doc ) ).to.have.property( 'nodeAfter' ).that.equals( z );
-		expect( new Position( [ 1, 0, 3 ], doc ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( f );
+		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( o );
+		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( z );
+		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 	} );
 
 	it( 'should equals another position with the same path', function() {
 		var Position = modules[ 'document/position' ];
 
-		var position = new Position( [ 1, 1, 2 ], doc );
-		var samePosition = new Position( [ 1, 1, 2 ], doc );
+		var position = new Position( [ 1, 1, 2 ], doc.root );
+		var samePosition = new Position( [ 1, 1, 2 ], doc.root );
 
 		expect( position.isEqual( samePosition ) ).to.be.true;
 	} );
@@ -244,8 +244,8 @@ describe( 'position', function() {
 	it( 'should not equals another position with the different path', function() {
 		var Position = modules[ 'document/position' ];
 
-		var position = new Position( [ 1, 1, 1 ], doc );
-		var differentNode = new Position( [ 1, 2, 2 ], doc );
+		var position = new Position( [ 1, 1, 1 ], doc.root );
+		var differentNode = new Position( [ 1, 2, 2 ], doc.root );
 
 		expect( position.isEqual( differentNode ) ).to.be.false;
 	} );

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

@@ -16,7 +16,7 @@ var modules = bender.amd.require(
 	'document/range' );
 
 describe( 'range iterator', function() {
-	var document, expectedItems;
+	var doc, expectedItems;
 
 	var root, img1, paragraph, charB, charA, charR, img2, charX;
 
@@ -33,8 +33,8 @@ describe( 'range iterator', function() {
 		CLOSING_TAG = PositionIterator.CLOSING_TAG;
 		CHARACTER = PositionIterator.CHARACTER;
 
-		document = new Document();
-		root = document.root;
+		doc = new Document();
+		root = doc.root;
 
 		// root
 		//  |- img1
@@ -85,7 +85,7 @@ describe( 'range iterator', function() {
 		var PositionIterator = modules[ 'document/positioniterator' ];
 		var Position = modules[ 'document/position' ];
 
-		var iterator = new PositionIterator( new Position( [ 0 ], document ) ); // begging of root
+		var iterator = new PositionIterator( new Position( [ 0 ], doc.root ) ); // begging of root
 		var i, len;
 
 		for ( i = 0, len = expectedItems.length; i < len; i++ ) {
@@ -98,7 +98,7 @@ describe( 'range iterator', function() {
 		var PositionIterator = modules[ 'document/positioniterator' ];
 		var Position = modules[ 'document/position' ];
 
-		var iterator = new PositionIterator( new Position( [ 2 ], document ) ); // ending of root
+		var iterator = new PositionIterator( new Position( [ 2 ], doc.root ) ); // ending of root
 
 		for ( var i = expectedItems.length - 1; i >= 0; i-- ) {
 			expect( iterator.previous() ).to.deep.equal( { done: false, value: expectedItems[ i ] } );
@@ -111,8 +111,8 @@ describe( 'range iterator', function() {
 		var Position = modules[ 'document/position' ];
 		var Range = modules[ 'document/range' ];
 
-		var start = new Position( [ 1, 0 ], document ); // p, 0
-		var end = new Position( [ 1, 3, 0 ], document ); // img, 0
+		var start = new Position( [ 1, 0 ], doc.root ); // p, 0
+		var end = new Position( [ 1, 3, 0 ], doc.root ); // img, 0
 
 		var iterator = new PositionIterator( new Range( start, end ) );
 
@@ -129,8 +129,8 @@ describe( 'range iterator', function() {
 		var Position = modules[ 'document/position' ];
 		var Range = modules[ 'document/range' ];
 
-		var start = new Position( [ 1, 0 ], document ); // p, 0
-		var end = new Position( [ 1, 3, 0 ], document ); // img, 0
+		var start = new Position( [ 1, 0 ], doc.root ); // p, 0
+		var end = new Position( [ 1, 3, 0 ], doc.root ); // img, 0
 
 		var iterator = new PositionIterator( new Range( start, end ), end );
 
@@ -146,8 +146,8 @@ describe( 'range iterator', function() {
 		var Position = modules[ 'document/position' ];
 		var Range = modules[ 'document/range' ];
 
-		var start = new Position( [ 0 ], document ); // begging of root
-		var end = new Position( [ 2 ], document ); // ending of root
+		var start = new Position( [ 0 ], doc.root ); // begging of root
+		var end = new Position( [ 2 ], doc.root ); // ending of root
 		var range = new Range( start, end );
 
 		var i = 0;

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

@@ -26,7 +26,7 @@ describe( 'RemoveOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'x' ) );
 
 		doc.applyOperation( new RemoveOperation(
-			new Position( [ 0 ], doc ),
+			new Position( [ 0 ], doc.root ),
 			doc.root.children[ 0 ],
 			doc.version ) );
 
@@ -47,7 +47,7 @@ describe( 'RemoveOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'r' ) );
 
 		doc.applyOperation( new RemoveOperation(
-			new Position( [ 0 ], doc ),
+			new Position( [ 0 ], doc.root ),
 			[ doc.root.children[ 0 ], doc.root.children[ 1 ], doc.root.children[ 2 ] ],
 			doc.version ) );
 
@@ -68,7 +68,7 @@ describe( 'RemoveOperation', function() {
 		doc.root.children.push( new Character( doc.root, 'r' ) );
 
 		doc.applyOperation( new RemoveOperation(
-			new Position( [ 1 ], doc ),
+			new Position( [ 1 ], doc.root ),
 			[ doc.root.children[ 1 ] ],
 			doc.version ) );
 
@@ -88,7 +88,7 @@ describe( 'RemoveOperation', function() {
 		var doc = new Document();
 
 		var nodes = [ new Character( null, 'b' ), new Character( null, 'a' ), new Character( null, 'r' ) ];
-		var position = new Position( [ 0 ], doc );
+		var position = new Position( [ 0 ], doc.root );
 
 		doc.root.children.push( nodes[ 0 ] );
 		doc.root.children.push( nodes[ 1 ] );
@@ -113,7 +113,7 @@ describe( 'RemoveOperation', function() {
 		var doc = new Document();
 
 		var nodes = [ new Character( null, 'b' ), new Character( null, 'a' ), new Character( null, 'r' ) ];
-		var position = new Position( [ 0 ], doc );
+		var position = new Position( [ 0 ], doc.root );
 
 		doc.root.children.push( nodes[ 0 ] );
 		doc.root.children.push( nodes[ 1 ] );