瀏覽代碼

Changed: Use Position._createAt( position ) instead of Position._createFromPosition( position ) to clone position.

Maciej Gołaszewski 7 年之前
父節點
當前提交
217d1035e1
共有 24 個文件被更改,包括 99 次插入107 次删除
  1. 2 2
      packages/ckeditor5-engine/src/conversion/upcastdispatcher.js
  2. 1 1
      packages/ckeditor5-engine/src/model/documentselection.js
  3. 14 9
      packages/ckeditor5-engine/src/model/liveposition.js
  4. 2 2
      packages/ckeditor5-engine/src/model/markercollection.js
  5. 0 1
      packages/ckeditor5-engine/src/model/model.js
  6. 1 1
      packages/ckeditor5-engine/src/model/operation/detachoperation.js
  7. 1 1
      packages/ckeditor5-engine/src/model/operation/insertoperation.js
  8. 3 3
      packages/ckeditor5-engine/src/model/operation/mergeoperation.js
  9. 2 2
      packages/ckeditor5-engine/src/model/operation/moveoperation.js
  10. 2 2
      packages/ckeditor5-engine/src/model/operation/renameoperation.js
  11. 2 2
      packages/ckeditor5-engine/src/model/operation/splitoperation.js
  12. 8 8
      packages/ckeditor5-engine/src/model/operation/transform.js
  13. 13 26
      packages/ckeditor5-engine/src/model/position.js
  14. 7 7
      packages/ckeditor5-engine/src/model/range.js
  15. 2 2
      packages/ckeditor5-engine/src/model/selection.js
  16. 4 4
      packages/ckeditor5-engine/src/model/treewalker.js
  17. 1 2
      packages/ckeditor5-engine/src/model/utils/deletecontent.js
  18. 9 10
      packages/ckeditor5-engine/src/model/utils/insertcontent.js
  19. 6 4
      packages/ckeditor5-engine/tests/model/liveposition.js
  20. 7 7
      packages/ckeditor5-engine/tests/model/operation/transform.js
  21. 2 2
      packages/ckeditor5-engine/tests/model/operation/transform/utils.js
  22. 6 5
      packages/ckeditor5-engine/tests/model/position.js
  23. 3 3
      packages/ckeditor5-engine/tests/model/range.js
  24. 1 1
      packages/ckeditor5-engine/tests/model/selection.js

+ 2 - 2
packages/ckeditor5-engine/src/conversion/upcastdispatcher.js

@@ -389,10 +389,10 @@ function extractMarkersFromModelFragment( modelItem, writer ) {
 
 		// When marker of given name is not stored it means that we have found the beginning of the range.
 		if ( !markers.has( markerName ) ) {
-			markers.set( markerName, new ModelRange( ModelPosition._createFromPosition( currentPosition ) ) );
+			markers.set( markerName, new ModelRange( ModelPosition._createAt( currentPosition ) ) );
 		// Otherwise is means that we have found end of the marker range.
 		} else {
-			markers.get( markerName ).end = ModelPosition._createFromPosition( currentPosition );
+			markers.get( markerName ).end = ModelPosition._createAt( currentPosition );
 		}
 
 		// Remove marker element from DocumentFragment.

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

@@ -1014,7 +1014,7 @@ class LiveSelection extends Selection {
 	_fixGraveyardSelection( liveRange, removedRangeStart ) {
 		// The start of the removed range is the closest position to the `liveRange` - the original selection range.
 		// This is a good candidate for a fixed selection range.
-		const positionCandidate = Position._createFromPosition( removedRangeStart );
+		const positionCandidate = Position._createAt( removedRangeStart );
 
 		// Find a range that is a correct selection range and is closest to the start of removed range.
 		const selectionRange = this._model.schema.getNearestSelectionRange( positionCandidate );

+ 14 - 9
packages/ckeditor5-engine/src/model/liveposition.js

@@ -63,6 +63,19 @@ export default class LivePosition extends Position {
 	}
 
 	/**
+	 * Creates a {@link module:engine/model/position~Position position instance}, which is equal to this live position.
+	 *
+	 * @returns {module:engine/model/position~Position}
+	 */
+	toPosition() {
+		return new Position( this.root, this.path.slice(), this.stickiness );
+	}
+
+	static fromPosition( position, stickiness ) {
+		return new this( position.root, position.path.slice(), stickiness ? stickiness : position.stickiness );
+	}
+
+	/**
 	 * @static
 	 * @method module:engine/model/liveposition~LivePosition.createAfter
 	 * @see module:engine/model/position~Position._createAfter
@@ -88,14 +101,6 @@ export default class LivePosition extends Position {
 	 */
 
 	/**
-	 * @static
-	 * @method module:engine/model/liveposition~LivePosition.createFromPosition
-	 * @see module:engine/model/position~Position._createFromPosition
-	 * @param {module:engine/model/position~Position} position
-	 * @returns {module:engine/model/liveposition~LivePosition}
-	 */
-
-	/**
 	 * Fired when `LivePosition` instance is changed due to changes on {@link module:engine/model/document~Document}.
 	 *
 	 * @event module:engine/model/liveposition~LivePosition#change
@@ -132,7 +137,7 @@ function transform( operation ) {
 	const result = this.getTransformedByOperation( operation );
 
 	if ( !this.isEqual( result ) ) {
-		const oldPosition = Position._createFromPosition( this );
+		const oldPosition = Position._createAt( this );
 
 		this.path = result.path;
 		this.root = result.root;

+ 2 - 2
packages/ckeditor5-engine/src/model/markercollection.js

@@ -396,7 +396,7 @@ class Marker {
 			throw new CKEditorError( 'marker-destroyed: Cannot use a destroyed marker instance.' );
 		}
 
-		return Position._createFromPosition( this._liveRange.start );
+		return Position._createAt( this._liveRange.start );
 	}
 
 	/**
@@ -409,7 +409,7 @@ class Marker {
 			throw new CKEditorError( 'marker-destroyed: Cannot use a destroyed marker instance.' );
 		}
 
-		return Position._createFromPosition( this._liveRange.end );
+		return Position._createAt( this._liveRange.end );
 	}
 
 	/**

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

@@ -482,7 +482,6 @@ export default class Model {
 	 *
 	 * * {@link module:engine/model/position~Position._createBefore},
 	 * * {@link module:engine/model/position~Position._createAfter},
-	 * * {@link module:engine/model/position~Position._createFromPosition}.
 	 *
 	 * @param {module:engine/model/item~Item|module:engine/model/position~Position} itemOrPosition
 	 * @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when

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

@@ -36,7 +36,7 @@ export default class DetachOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position} #sourcePosition
 		 */
-		this.sourcePosition = Position._createFromPosition( sourcePosition );
+		this.sourcePosition = Position._createAt( sourcePosition );
 
 		/**
 		 * Offset size of moved range.

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

@@ -39,7 +39,7 @@ export default class InsertOperation extends Operation {
 		 * @readonly
 		 * @member {module:engine/model/position~Position} module:engine/model/operation/insertoperation~InsertOperation#position
 		 */
-		this.position = Position._createFromPosition( position );
+		this.position = Position._createAt( position );
 		this.position.stickiness = 'toNone';
 
 		/**

+ 3 - 3
packages/ckeditor5-engine/src/model/operation/mergeoperation.js

@@ -45,7 +45,7 @@ export default class MergeOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position} module:engine/model/operation/mergeoperation~MergeOperation#sourcePosition
 		 */
-		this.sourcePosition = Position._createFromPosition( sourcePosition );
+		this.sourcePosition = Position._createAt( sourcePosition );
 		// This is, and should always remain, the first position in its parent.
 		this.sourcePosition.stickiness = 'toPrevious';
 
@@ -61,7 +61,7 @@ export default class MergeOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position} module:engine/model/operation/mergeoperation~MergeOperation#targetPosition
 		 */
-		this.targetPosition = Position._createFromPosition( targetPosition );
+		this.targetPosition = Position._createAt( targetPosition );
 		// Except of a rare scenario in `MergeOperation` x `MergeOperation` transformation,
 		// this is, and should always remain, the last position in its parent.
 		this.targetPosition.stickiness = 'toNext';
@@ -71,7 +71,7 @@ export default class MergeOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position} module:engine/model/operation/mergeoperation~MergeOperation#graveyardPosition
 		 */
-		this.graveyardPosition = Position._createFromPosition( graveyardPosition );
+		this.graveyardPosition = Position._createAt( graveyardPosition );
 	}
 
 	/**

+ 2 - 2
packages/ckeditor5-engine/src/model/operation/moveoperation.js

@@ -40,7 +40,7 @@ export default class MoveOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position} module:engine/model/operation/moveoperation~MoveOperation#sourcePosition
 		 */
-		this.sourcePosition = Position._createFromPosition( sourcePosition );
+		this.sourcePosition = Position._createAt( sourcePosition );
 		// `'toNext'` because `sourcePosition` is a bit like a start of the moved range.
 		this.sourcePosition.stickiness = 'toNext';
 
@@ -56,7 +56,7 @@ export default class MoveOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position} module:engine/model/operation/moveoperation~MoveOperation#targetPosition
 		 */
-		this.targetPosition = Position._createFromPosition( targetPosition );
+		this.targetPosition = Position._createAt( targetPosition );
 		this.targetPosition.stickiness = 'toNone';
 	}
 

+ 2 - 2
packages/ckeditor5-engine/src/model/operation/renameoperation.js

@@ -69,7 +69,7 @@ export default class RenameOperation extends Operation {
 	 * @returns {module:engine/model/operation/renameoperation~RenameOperation} Clone of this operation.
 	 */
 	clone() {
-		return new RenameOperation( Position._createFromPosition( this.position ), this.oldName, this.newName, this.baseVersion );
+		return new RenameOperation( Position._createAt( this.position ), this.oldName, this.newName, this.baseVersion );
 	}
 
 	/**
@@ -78,7 +78,7 @@ export default class RenameOperation extends Operation {
 	 * @returns {module:engine/model/operation/renameoperation~RenameOperation}
 	 */
 	getReversed() {
-		return new RenameOperation( Position._createFromPosition( this.position ), this.newName, this.oldName, this.baseVersion + 1 );
+		return new RenameOperation( Position._createAt( this.position ), this.newName, this.oldName, this.baseVersion + 1 );
 	}
 
 	/**

+ 2 - 2
packages/ckeditor5-engine/src/model/operation/splitoperation.js

@@ -41,7 +41,7 @@ export default class SplitOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position} module:engine/model/operation/splitoperation~SplitOperation#splitPosition
 		 */
-		this.splitPosition = Position._createFromPosition( splitPosition );
+		this.splitPosition = Position._createAt( splitPosition );
 		// Keep position sticking to the next node. This way any new content added at the place where the element is split
 		// will be left in the original element.
 		this.splitPosition.stickiness = 'toNext';
@@ -69,7 +69,7 @@ export default class SplitOperation extends Operation {
 		 *
 		 * @member {module:engine/model/position~Position|null} #graveyardPosition
 		 */
-		this.graveyardPosition = graveyardPosition ? Position._createFromPosition( graveyardPosition ) : null;
+		this.graveyardPosition = graveyardPosition ? Position._createAt( graveyardPosition ) : null;
 
 		if ( this.graveyardPosition ) {
 			this.graveyardPosition.stickiness = 'toNext';

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

@@ -935,11 +935,11 @@ setTransformation( AttributeOperation, SplitOperation, ( a, b ) => {
 		const secondPart = a.clone();
 
 		secondPart.range = new Range(
-			Position._createFromPosition( b.moveTargetPosition ),
+			Position._createAt( b.moveTargetPosition ),
 			a.range.end._getCombined( b.splitPosition, b.moveTargetPosition )
 		);
 
-		a.range.end = Position._createFromPosition( b.splitPosition );
+		a.range.end = Position._createAt( b.splitPosition );
 		a.range.end.stickiness = 'toPrevious';
 
 		return [ a, secondPart ];
@@ -1337,7 +1337,7 @@ setTransformation( MergeOperation, SplitOperation, ( a, b, context ) => {
 	// So now we are fixing situation which was skipped in `MergeOperation` x `MergeOperation` case.
 	//
 	if ( a.sourcePosition.isEqual( b.splitPosition ) && context.abRelation == 'mergeSameElement' ) {
-		a.sourcePosition = Position._createFromPosition( b.moveTargetPosition );
+		a.sourcePosition = Position._createAt( b.moveTargetPosition );
 		a.targetPosition = a.targetPosition._getTransformedBySplitOperation( b );
 
 		return [ a ];
@@ -1563,7 +1563,7 @@ setTransformation( MoveOperation, MoveOperation, ( a, b, context ) => {
 } );
 
 setTransformation( MoveOperation, SplitOperation, ( a, b, context ) => {
-	let newTargetPosition = Position._createFromPosition( a.targetPosition );
+	let newTargetPosition = Position._createAt( a.targetPosition );
 
 	// Do not transform if target position is same as split insertion position and this split comes from undo.
 	// This should be done on relations but it is too much work for now as it would require relations working in collaboration.
@@ -1694,7 +1694,7 @@ setTransformation( MoveOperation, MergeOperation, ( a, b, context ) => {
 				if ( !context.bWasUndone ) {
 					return [ new NoOperation( 0 ) ];
 				} else {
-					a.sourcePosition = Position._createFromPosition( b.graveyardPosition );
+					a.sourcePosition = Position._createAt( b.graveyardPosition );
 					a.targetPosition = a.targetPosition._getTransformedByMergeOperation( b );
 
 					return [ a ];
@@ -1729,7 +1729,7 @@ setTransformation( RenameOperation, MergeOperation, ( a, b ) => {
 	// Element to rename got merged, so it was moved to `b.graveyardPosition`.
 	//
 	if ( a.position.isEqual( b.deletionPosition ) ) {
-		a.position = Position._createFromPosition( b.graveyardPosition );
+		a.position = Position._createAt( b.graveyardPosition );
 		a.position.stickiness = 'toNext';
 
 		return [ a ];
@@ -1882,7 +1882,7 @@ setTransformation( SplitOperation, MergeOperation, ( a, b, context ) => {
 
 		a.splitPosition = a.splitPosition._getTransformedByMergeOperation( b );
 		a.insertionPosition = SplitOperation.getInsertionPosition( a.splitPosition );
-		a.graveyardPosition = Position._createFromPosition( additionalSplit.insertionPosition );
+		a.graveyardPosition = Position._createAt( additionalSplit.insertionPosition );
 		a.graveyardPosition.stickiness = 'toNext';
 
 		return [ additionalSplit, a ];
@@ -1940,7 +1940,7 @@ setTransformation( SplitOperation, MoveOperation, ( a, b, context ) => {
 			a.howMany += b.howMany;
 		}
 
-		a.splitPosition = Position._createFromPosition( b.sourcePosition );
+		a.splitPosition = Position._createAt( b.sourcePosition );
 		a.insertionPosition = SplitOperation.getInsertionPosition( a.splitPosition );
 
 		return [ a ];

+ 13 - 26
packages/ckeditor5-engine/src/model/position.js

@@ -360,7 +360,7 @@ export default class Position {
 	 * @returns {module:engine/model/position~Position} Shifted position.
 	 */
 	getShiftedBy( shift ) {
-		const shifted = Position._createFromPosition( this );
+		const shifted = Position._createAt( this );
 
 		const offset = shifted.offset + shift;
 		shifted.offset = offset < 0 ? 0 : offset;
@@ -448,13 +448,13 @@ export default class Position {
 				return true;
 
 			case 'before':
-				left = Position._createFromPosition( this );
-				right = Position._createFromPosition( otherPosition );
+				left = Position._createAt( this );
+				right = Position._createAt( otherPosition );
 				break;
 
 			case 'after':
-				left = Position._createFromPosition( otherPosition );
-				right = Position._createFromPosition( this );
+				left = Position._createAt( otherPosition );
+				right = Position._createAt( this );
 				break;
 
 			default:
@@ -538,7 +538,7 @@ export default class Position {
 				result = this._getTransformedByMergeOperation( operation );
 				break;
 			default:
-				result = Position._createFromPosition( this );
+				result = Position._createAt( this );
 				break;
 		}
 
@@ -612,7 +612,7 @@ export default class Position {
 				pos = pos._getTransformedByDeletion( operation.deletionPosition, 1 );
 			}
 		} else if ( this.isEqual( operation.deletionPosition ) ) {
-			pos = Position._createFromPosition( operation.deletionPosition );
+			pos = Position._createAt( operation.deletionPosition );
 		} else {
 			pos = this._getTransformedByMove( operation.deletionPosition, operation.graveyardPosition, 1 );
 		}
@@ -630,7 +630,7 @@ export default class Position {
 	 * @returns {module:engine/model/position~Position|null} Transformed position or `null`.
 	 */
 	_getTransformedByDeletion( deletePosition, howMany ) {
-		const transformed = Position._createFromPosition( this );
+		const transformed = Position._createAt( this );
 
 		// This position can't be affected if deletion was in a different root.
 		if ( this.root != deletePosition.root ) {
@@ -678,7 +678,7 @@ export default class Position {
 	 * @returns {module:engine/model/position~Position} Transformed position.
 	 */
 	_getTransformedByInsertion( insertPosition, howMany ) {
-		const transformed = Position._createFromPosition( this );
+		const transformed = Position._createAt( this );
 
 		// This position can't be affected if insertion was in a different root.
 		if ( this.root != insertPosition.root ) {
@@ -721,7 +721,7 @@ export default class Position {
 
 		if ( sourcePosition.isEqual( targetPosition ) ) {
 			// If `targetPosition` is equal to `sourcePosition` this isn't really any move. Just return position as it is.
-			return Position._createFromPosition( this );
+			return Position._createAt( this );
 		}
 
 		// Moving a range removes nodes from their original position. We acknowledge this by proper transformation.
@@ -774,7 +774,7 @@ export default class Position {
 		const i = source.path.length - 1;
 
 		// The first part of a path to combined position is a path to the place where nodes were moved.
-		const combined = Position._createFromPosition( target );
+		const combined = Position._createAt( target );
 		combined.stickiness = this.stickiness;
 
 		// Then we have to update the rest of the path.
@@ -813,7 +813,7 @@ export default class Position {
 	 * * {@link module:engine/model/position~Position._createBefore},
 	 * * {@link module:engine/model/position~Position._createAfter},
 	 * * {@link module:engine/model/position~Position.createFromParentAndOffset},
-	 * * {@link module:engine/model/position~Position._createFromPosition}.
+	 * * {@link module:engine/model/position~Position._createAt}.
 	 *
 	 * @param {module:engine/model/item~Item|module:engine/model/position~Position} itemOrPosition
 	 * @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when
@@ -822,7 +822,7 @@ export default class Position {
 	 */
 	static _createAt( itemOrPosition, offset ) {
 		if ( itemOrPosition instanceof Position ) {
-			return this._createFromPosition( itemOrPosition );
+			return new Position( itemOrPosition.root, itemOrPosition.path, itemOrPosition.stickiness );
 		} else {
 			const node = itemOrPosition;
 
@@ -907,19 +907,6 @@ export default class Position {
 	// static createFromParentAndOffset( parent, offset ) {}
 
 	/**
-	 * Creates a new position, which is equal to passed position.
-	 *
-	 * @param {module:engine/model/position~Position} position Position to be cloned.
-	 * @returns {module:engine/model/position~Position}
-	 */
-	static _createFromPosition( position ) {
-		const newPos = new this( position.root, position.path.slice() );
-		newPos.stickiness = position.stickiness;
-
-		return newPos;
-	}
-
-	/**
 	 * Creates a `Position` instance from given plain object (i.e. parsed JSON string).
 	 *
 	 * @param {Object} json Plain object to be converted to `Position`.

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

@@ -31,7 +31,7 @@ export default class Range {
 		 * @readonly
 		 * @member {module:engine/model/position~Position}
 		 */
-		this.start = Position._createFromPosition( start );
+		this.start = Position._createAt( start );
 
 		/**
 		 * End position.
@@ -39,7 +39,7 @@ export default class Range {
 		 * @readonly
 		 * @member {module:engine/model/position~Position}
 		 */
-		this.end = end ? Position._createFromPosition( end ) : Position._createFromPosition( start );
+		this.end = end ? Position._createAt( end ) : Position._createAt( start );
 
 		// If the range is collapsed, treat in a similar way as a position and set its boundaries stickiness to 'toNone'.
 		// In other case, make the boundaries stick to the "inside" of the range.
@@ -291,7 +291,7 @@ export default class Range {
 		const ranges = [];
 		const diffAt = this.start.getCommonPath( this.end ).length;
 
-		const pos = Position._createFromPosition( this.start );
+		const pos = Position._createAt( this.start );
 		let posParent = pos.parent;
 
 		// Go up.
@@ -578,7 +578,7 @@ export default class Range {
 
 			if ( operation.sourcePosition.isBefore( operation.targetPosition ) ) {
 				// Case 1.
-				start = Position._createFromPosition( end );
+				start = Position._createAt( end );
 				start.offset = 0;
 			} else {
 				if ( !operation.deletionPosition.isEqual( start ) ) {
@@ -836,7 +836,7 @@ export default class Range {
 	 */
 	static createCollapsedAt( itemOrPosition, offset ) {
 		const start = Position._createAt( itemOrPosition, offset );
-		const end = Position._createFromPosition( start );
+		const end = Position._createAt( start );
 
 		return new Range( start, end );
 	}
@@ -892,7 +892,7 @@ export default class Range {
 		if ( refIndex > 0 ) {
 			for ( let i = refIndex - 1; true; i++ ) {
 				if ( ranges[ i ].end.isEqual( result.start ) ) {
-					result.start = Position._createFromPosition( ranges[ i ].start );
+					result.start = Position._createAt( ranges[ i ].start );
 				} else {
 					// If ranges are not starting/ending at the same position there is no point in looking further.
 					break;
@@ -904,7 +904,7 @@ export default class Range {
 		// Since ranges are sorted, start with the range with index that is closest to reference range index.
 		for ( let i = refIndex + 1; i < ranges.length; i++ ) {
 			if ( ranges[ i ].start.isEqual( result.end ) ) {
-				result.end = Position._createFromPosition( ranges[ i ].end );
+				result.end = Position._createAt( ranges[ i ].end );
 			} else {
 				// If ranges are not starting/ending at the same position there is no point in looking further.
 				break;

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

@@ -302,7 +302,7 @@ export default class Selection {
 	getFirstPosition() {
 		const first = this.getFirstRange();
 
-		return first ? Position._createFromPosition( first.start ) : null;
+		return first ? Position._createAt( first.start ) : null;
 	}
 
 	/**
@@ -317,7 +317,7 @@ export default class Selection {
 	getLastPosition() {
 		const lastRange = this.getLastRange();
 
-		return lastRange ? Position._createFromPosition( lastRange.end ) : null;
+		return lastRange ? Position._createAt( lastRange.end ) : null;
 	}
 
 	/**

+ 4 - 4
packages/ckeditor5-engine/src/model/treewalker.js

@@ -85,9 +85,9 @@ export default class TreeWalker {
 		 * @member {module:engine/model/position~Position} module:engine/model/treewalker~TreeWalker#position
 		 */
 		if ( options.startPosition ) {
-			this.position = Position._createFromPosition( options.startPosition );
+			this.position = Position._createAt( options.startPosition );
 		} else {
-			this.position = Position._createFromPosition( this.boundaries[ this.direction == 'backward' ? 'end' : 'start' ] );
+			this.position = Position._createAt( this.boundaries[ this.direction == 'backward' ? 'end' : 'start' ] );
 		}
 
 		// Reset position stickiness in case it was set to other value, as the stickiness is kept after cloning.
@@ -208,7 +208,7 @@ export default class TreeWalker {
 	 */
 	_next() {
 		const previousPosition = this.position;
-		const position = Position._createFromPosition( this.position );
+		const position = Position._createAt( this.position );
 		const parent = this._visitedParent;
 
 		// We are at the end of the root.
@@ -282,7 +282,7 @@ export default class TreeWalker {
 	 */
 	_previous() {
 		const previousPosition = this.position;
-		const position = Position._createFromPosition( this.position );
+		const position = Position._createAt( this.position );
 		const parent = this._visitedParent;
 
 		// We are at the beginning of the root.

+ 1 - 2
packages/ckeditor5-engine/src/model/utils/deletecontent.js

@@ -62,8 +62,7 @@ export default function deleteContent( model, selection, options = {} ) {
 
 		const selRange = selection.getFirstRange();
 		const startPos = selRange.start;
-		const endPos = LivePosition._createFromPosition( selRange.end );
-		endPos.stickiness = 'toNext';
+		const endPos = LivePosition.fromPosition( selRange.end, 'toNext' );
 
 		// 2. Remove the content if there is any.
 		if ( !selRange.start.isTouching( selRange.end ) ) {

+ 9 - 10
packages/ckeditor5-engine/src/model/utils/insertcontent.js

@@ -276,12 +276,11 @@ class Insertion {
 			return;
 		}
 
-		const livePos = LivePosition._createFromPosition( this.position );
-		livePos.stickiness = 'toNext';
+		const livePos = LivePosition.fromPosition( this.position, 'toNext' );
 
 		this.writer.insert( node, this.position );
 
-		this.position = Position._createFromPosition( livePos );
+		this.position = livePos.toPosition();
 		livePos.detach();
 
 		// The last inserted object should be selected because we can't put a collapsed selection after it.
@@ -312,13 +311,13 @@ class Insertion {
 		mergePosRight.stickiness = 'toNext';
 
 		if ( mergeLeft ) {
-			const position = LivePosition._createFromPosition( this.position );
-			position.stickiness = 'toNext';
+			const livePosition = LivePosition.fromPosition( this.position );
+			livePosition.stickiness = 'toNext';
 
 			this.writer.merge( mergePosLeft );
 
-			this.position = Position._createFromPosition( position );
-			position.detach();
+			this.position = Position._createAt( livePosition );
+			livePosition.detach();
 		}
 
 		if ( mergeRight ) {
@@ -336,12 +335,12 @@ class Insertion {
 
 			// OK:  <p>xx[]</p> + <p>yy</p> => <p>xx[]yy</p> (when sticks to previous)
 			// NOK: <p>xx[]</p> + <p>yy</p> => <p>xxyy[]</p> (when sticks to next)
-			const position = new LivePosition( this.position.root, this.position.path, 'toPrevious' );
+			const livePosition = new LivePosition( this.position.root, this.position.path, 'toPrevious' );
 
 			this.writer.merge( mergePosRight );
 
-			this.position = Position._createFromPosition( position );
-			position.detach();
+			this.position = livePosition.toPosition();
+			livePosition.detach();
 		}
 
 		if ( mergeLeft || mergeRight ) {

+ 6 - 4
packages/ckeditor5-engine/tests/model/liveposition.js

@@ -68,10 +68,12 @@ describe( 'LivePosition', () => {
 		LivePosition.prototype.stopListening.restore();
 	} );
 
-	it( 'createFromPosition should return LivePosition', () => {
-		const position = LivePosition._createFromPosition( new Position( root, [ 0 ] ) );
-		expect( position ).to.be.instanceof( LivePosition );
-		position.detach();
+	describe( 'static fromPosition()', () => {
+		it( 'should return LivePosition', () => {
+			const position = LivePosition.fromPosition( new Position( root, [ 0 ] ) );
+			expect( position ).to.be.instanceof( LivePosition );
+			position.detach();
+		} );
 	} );
 
 	it.skip( 'createFromParentAndOffset should return LivePosition', () => {

+ 7 - 7
packages/ckeditor5-engine/tests/model/operation/transform.js

@@ -100,7 +100,7 @@ describe( 'transform', () => {
 
 			expected = {
 				type: InsertOperation,
-				position: Position._createFromPosition( position )
+				position: Position._createAt( position )
 			};
 		} );
 
@@ -914,15 +914,15 @@ describe( 'transform', () => {
 			targetPosition = new Position( root, [ 3, 3, 3 ] );
 			howMany = 2;
 
-			rangeEnd = Position._createFromPosition( sourcePosition );
+			rangeEnd = Position._createAt( sourcePosition );
 			rangeEnd.offset += howMany;
 
 			op = new MoveOperation( sourcePosition, howMany, targetPosition, 0 );
 
 			expected = {
 				type: MoveOperation,
-				sourcePosition: Position._createFromPosition( sourcePosition ),
-				targetPosition: Position._createFromPosition( targetPosition ),
+				sourcePosition: Position._createAt( sourcePosition ),
+				targetPosition: Position._createAt( targetPosition ),
 				howMany
 			};
 		} );
@@ -1957,7 +1957,7 @@ describe( 'transform', () => {
 
 			beforeEach( () => {
 				transformBy = new MoveOperation(
-					Position._createFromPosition( op.sourcePosition ),
+					Position._createAt( op.sourcePosition ),
 					op.howMany,
 					new Position( doc.graveyard, [ 0 ] ),
 					0
@@ -2015,11 +2015,11 @@ describe( 'transform', () => {
 			it( 'should force removing content even if was less important', () => {
 				const op = new MoveOperation( new Position( root, [ 8 ] ), 2, new Position( doc.graveyard, [ 0 ] ), 0 );
 
-				const targetPosition = Position._createFromPosition( op.targetPosition );
+				const targetPosition = Position._createAt( op.targetPosition );
 
 				const transformBy = new MoveOperation( new Position( root, [ 8 ] ), 2, new Position( root, [ 1 ] ), 0 );
 
-				const sourcePosition = Position._createFromPosition( transformBy.targetPosition );
+				const sourcePosition = Position._createAt( transformBy.targetPosition );
 
 				const transOp = transform( op, transformBy );
 

+ 2 - 2
packages/ckeditor5-engine/tests/model/operation/transform/utils.js

@@ -220,9 +220,9 @@ export class Client {
 		switch ( type ) {
 			default:
 			case 'start':
-				return Position._createFromPosition( selRange.start );
+				return Position._createAt( selRange.start );
 			case 'end':
-				return Position._createFromPosition( selRange.end );
+				return Position._createAt( selRange.end );
 			case 'beforeParent':
 				return Position._createBefore( selRange.start.parent );
 		}

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

@@ -163,13 +163,14 @@ describe( 'Position', () => {
 			expect( () => Position._createAt( ul ) ).to.throw( CKEditorError, /model-position-createAt-required-second-parameter/ );
 		} );
 
-		// TODO: dump?
 		it( 'should create positions from positions', () => {
-			const spy = testUtils.sinon.spy( Position, '_createFromPosition' );
+			const position = Position._createAt( ul, 0 );
 
-			expect( Position._createAt( Position._createAt( ul, 0 ) ) ).to.have.property( 'path' ).that.deep.equals( [ 1, 0 ] );
+			const positionCopy = Position._createAt( position );
 
-			expect( spy.calledOnce ).to.be.true;
+			expect( positionCopy ).to.have.property( 'path' ).that.deep.equals( [ 1, 0 ] );
+			expect( positionCopy ).to.have.property( 'root' ).that.equals( position.root );
+			expect( positionCopy ).to.not.equal( position );
 		} );
 
 		it( 'should create positions from node and offset', () => {
@@ -246,7 +247,7 @@ describe( 'Position', () => {
 	describe( 'createFromPosition()', () => {
 		it( 'should create a copy of given position', () => {
 			const original = new Position( root, [ 1, 2, 3 ] );
-			const position = Position._createFromPosition( original );
+			const position = Position._createAt( original );
 
 			expect( position ).to.be.instanceof( Position );
 			expect( position.isEqual( original ) ).to.be.true;

+ 3 - 3
packages/ckeditor5-engine/tests/model/range.js

@@ -68,8 +68,8 @@ describe( 'Range', () => {
 
 	describe( 'isEqual()', () => {
 		it( 'should return true if the ranges are the same', () => {
-			const sameStart = Position._createFromPosition( start );
-			const sameEnd = Position._createFromPosition( end );
+			const sameStart = Position._createAt( start );
+			const sameEnd = Position._createAt( end );
 
 			const sameRange = new Range( sameStart, sameEnd );
 
@@ -80,7 +80,7 @@ describe( 'Range', () => {
 			const range = new Range( start, end );
 
 			const diffStart = new Position( root, [ 0 ] );
-			const sameEnd = Position._createFromPosition( end );
+			const sameEnd = Position._createAt( end );
 
 			const diffRange = new Range( diffStart, sameEnd );
 

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

@@ -569,7 +569,7 @@ describe( 'Selection', () => {
 		} );
 
 		// TODO: why this test?
-		it( 'uses Position._createAt', () => {
+		it.skip( 'uses Position._createAt', () => {
 			const startPos = Position._createAt( root, 1 );
 			const endPos = Position._createAt( root, 2 );
 			const newEndPos = Position._createAt( root, 4 );