8
0
Просмотр исходного кода

Merge branch 't/1461' into t/ot-followups

Szymon Cofalik 7 лет назад
Родитель
Сommit
f8c78206f5

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

@@ -60,7 +60,6 @@ export default class DetachOperation extends Operation {
 		if ( this.sourcePosition.root.document ) {
 			/**
 			 * Cannot detach document node.
-			 * Use {@link module:engine/model/operation/removeoperation~RemoveOperation remove operation} instead.
 			 *
 			 * @error detach-operation-on-document-node
 			 */

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

@@ -10,7 +10,7 @@
 import Operation from './operation';
 import Position from '../position';
 import NodeList from '../nodelist';
-import RemoveOperation from './removeoperation';
+import MoveOperation from './moveoperation';
 import { _insert, _normalizeNodes } from './utils';
 import Text from '../text';
 import Element from '../element';
@@ -87,13 +87,13 @@ export default class InsertOperation extends Operation {
 	/**
 	 * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
 	 *
-	 * @returns {module:engine/model/operation/removeoperation~RemoveOperation}
+	 * @returns {module:engine/model/operation/moveoperation~MoveOperation}
 	 */
 	getReversed() {
 		const graveyard = this.position.root.document.graveyard;
 		const gyPosition = new Position( graveyard, [ 0 ] );
 
-		return new RemoveOperation( this.position, this.nodes.maxOffset, gyPosition, this.baseVersion + 1 );
+		return new MoveOperation( this.position, this.nodes.maxOffset, gyPosition, this.baseVersion + 1 );
 	}
 
 	/**

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

@@ -64,6 +64,12 @@ export default class MoveOperation extends Operation {
 	 * @inheritDoc
 	 */
 	get type() {
+		if ( this.targetPosition.root.rootName == '$graveyard' ) {
+			return 'remove';
+		} else if ( this.sourcePosition.root.rootName == '$graveyard' ) {
+			return 'reinsert';
+		}
+
 		return 'move';
 	}
 

+ 0 - 4
packages/ckeditor5-engine/src/model/operation/operationfactory.js

@@ -13,8 +13,6 @@ import MarkerOperation from '../operation/markeroperation';
 import MoveOperation from '../operation/moveoperation';
 import NoOperation from '../operation/nooperation';
 import Operation from '../operation/operation';
-import ReinsertOperation from '../operation/reinsertoperation';
-import RemoveOperation from '../operation/removeoperation';
 import RenameOperation from '../operation/renameoperation';
 import RootAttributeOperation from '../operation/rootattributeoperation';
 import SplitOperation from '../operation/splitoperation';
@@ -29,8 +27,6 @@ operations[ MarkerOperation.className ] = MarkerOperation;
 operations[ MoveOperation.className ] = MoveOperation;
 operations[ NoOperation.className ] = NoOperation;
 operations[ Operation.className ] = Operation;
-operations[ ReinsertOperation.className ] = ReinsertOperation;
-operations[ RemoveOperation.className ] = RemoveOperation;
 operations[ RenameOperation.className ] = RenameOperation;
 operations[ RootAttributeOperation.className ] = RootAttributeOperation;
 operations[ SplitOperation.className ] = SplitOperation;

+ 0 - 76
packages/ckeditor5-engine/src/model/operation/reinsertoperation.js

@@ -1,76 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module engine/model/operation/reinsertoperation
- */
-
-import MoveOperation from './moveoperation';
-import RemoveOperation from './removeoperation';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
-
-/**
- * Operation to reinsert previously removed nodes back to the non-graveyard root. This operation acts like
- * {@link module:engine/model/operation/moveoperation~MoveOperation} but it returns
- * {@link module:engine/model/operation/removeoperation~RemoveOperation} when reversed
- * and fires different change event.
- */
-export default class ReinsertOperation extends MoveOperation {
-	/**
-	 * Position where nodes will be re-inserted.
-	 *
-	 * @type {module:engine/model/position~Position}
-	 */
-	get position() {
-		return this.targetPosition;
-	}
-
-	/**
-	 * @param {module:engine/model/position~Position} pos
-	 */
-	set position( pos ) {
-		this.targetPosition = pos;
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	get type() {
-		return 'reinsert';
-	}
-
-	/**
-	 * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
-	 *
-	 * @returns {module:engine/model/operation/removeoperation~RemoveOperation}
-	 */
-	getReversed() {
-		const newTargetPosition = this.sourcePosition._getTransformedByInsertion( this.targetPosition, this.howMany );
-
-		return new RemoveOperation( this.getMovedRangeStart(), this.howMany, newTargetPosition, this.baseVersion + 1 );
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	_validate() {
-		super._validate();
-
-		if ( !this.sourcePosition.root.document ) {
-			throw new CKEditorError( 'reinsert-operation-on-detached-item: Cannot reinsert detached item.' );
-		}
-
-		if ( !this.targetPosition.root.document ) {
-			throw new CKEditorError( 'reinsert-operation-to-detached-parent: Cannot reinsert item to detached parent.' );
-		}
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	static get className() {
-		return 'engine.model.operation.ReinsertOperation';
-	}
-}

+ 0 - 60
packages/ckeditor5-engine/src/model/operation/removeoperation.js

@@ -1,60 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module engine/model/operation/removeoperation
- */
-
-import MoveOperation from './moveoperation';
-import ReinsertOperation from './reinsertoperation';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
-
-/**
- * Operation to remove a range of nodes.
- */
-export default class RemoveOperation extends MoveOperation {
-	/**
-	 * @inheritDoc
-	 */
-	get type() {
-		return 'remove';
-	}
-
-	/**
-	 * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
-	 *
-	 * @returns {module:engine/model/operation/reinsertoperation~ReinsertOperation|module:engine/model/operation/nooperation~NoOperation}
-	 */
-	getReversed() {
-		const newTargetPosition = this.sourcePosition._getTransformedByInsertion( this.targetPosition, this.howMany );
-
-		return new ReinsertOperation( this.getMovedRangeStart(), this.howMany, newTargetPosition, this.baseVersion + 1 );
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	_validate() {
-		super._validate();
-
-		if ( !this.sourcePosition.root.document ) {
-			/**
-			 * Item that is going to be removed needs to be a {@link module:engine/model/document~Document document} child.
-			 * To remove Item from detached document fragment use
-			 * {@link module:engine/model/operation/detachoperation~DetachOperation DetachOperation}.
-			 *
-			 * @error remove-operation-on-detached-item
-			 */
-			throw new CKEditorError( 'remove-operation-on-detached-item: Cannot remove detached item.' );
-		}
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	static get className() {
-		return 'engine.model.operation.RemoveOperation';
-	}
-}

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

@@ -3,8 +3,6 @@ import AttributeOperation from './attributeoperation';
 import RenameOperation from './renameoperation';
 import MarkerOperation from './markeroperation';
 import MoveOperation from './moveoperation';
-import RemoveOperation from './removeoperation';
-import ReinsertOperation from './reinsertoperation';
 import RootAttributeOperation from './rootattributeoperation';
 import MergeOperation from './mergeoperation';
 import SplitOperation from './splitoperation';
@@ -29,32 +27,10 @@ function setTransformation( OperationA, OperationB, transformationFunction ) {
 }
 
 function getTransformation( a, b ) {
-	const OperationA = a.constructor;
-	const OperationB = b.constructor;
+	const aGroup = transformations.get( a.constructor );
 
-	const aGroups = new Set();
-	const aGroup = transformations.get( OperationA );
-
-	if ( aGroup ) {
-		aGroups.add( aGroup );
-	}
-
-	for ( const Operation of transformations.keys() ) {
-		if ( a instanceof Operation ) {
-			aGroups.add( transformations.get( Operation ) );
-		}
-	}
-
-	for ( const group of aGroups ) {
-		if ( group.has( OperationB ) ) {
-			return group.get( OperationB );
-		}
-
-		for ( const Operation of group.keys() ) {
-			if ( b instanceof Operation ) {
-				return group.get( Operation );
-			}
-		}
+	if ( aGroup && aGroup.has( b.constructor ) ) {
+		return aGroup.get( b.constructor );
 	}
 
 	return noUpdateTransformation;
@@ -707,7 +683,7 @@ setTransformation( MergeOperation, MoveOperation, ( a, b, context ) => {
 	//
 	const removedRange = Range.createFromPositionAndShift( b.sourcePosition, b.howMany );
 
-	if ( b instanceof RemoveOperation && !context.wasUndone( b ) ) {
+	if ( b.type == 'remove' && !context.wasUndone( b ) ) {
 		if ( a.deletionPosition.hasSameParentAs( b.sourcePosition ) && removedRange.containsPosition( a.sourcePosition ) ) {
 			return getNoOp();
 		}
@@ -926,9 +902,9 @@ setTransformation( MoveOperation, MoveOperation, ( a, b, context ) => {
 	//
 	// If only one of operations is a remove operation, we force remove operation to be the "stronger" one
 	// to provide more expected results.
-	if ( a instanceof RemoveOperation && !( b instanceof RemoveOperation ) ) {
+	if ( a.type == 'remove' && b.type != 'remove' ) {
 		aIsStrong = true;
-	} else if ( !( a instanceof RemoveOperation ) && b instanceof RemoveOperation ) {
+	} else if ( a.type != 'remove' && b.type == 'remove' ) {
 		aIsStrong = false;
 	}
 
@@ -1050,7 +1026,7 @@ setTransformation( MoveOperation, MergeOperation, ( a, b, context ) => {
 	const movedRange = Range.createFromPositionAndShift( a.sourcePosition, a.howMany );
 
 	if ( b.deletionPosition.hasSameParentAs( a.sourcePosition ) && movedRange.containsPosition( b.sourcePosition ) ) {
-		if ( a instanceof RemoveOperation ) {
+		if ( a.type == 'remove' ) {
 			// Case 1:	The element to remove got merged.
 			//			Merge operation does support merging elements which are not siblings. So it would not be a problem
 			//			from technical point of view. However, if the element was removed, the intention of the user
@@ -1767,25 +1743,12 @@ function makeMoveOperationsFromRanges( ranges, targetPosition ) {
 }
 
 function makeMoveOperation( range, targetPosition ) {
-	// We want to keep correct operation class.
-	let OperationClass;
-
-	if ( targetPosition.root.rootName == '$graveyard' ) {
-		OperationClass = RemoveOperation;
-	} else if ( range.start.root.rootName == '$graveyard' ) {
-		OperationClass = ReinsertOperation;
-	} else {
-		OperationClass = MoveOperation;
-	}
-
 	targetPosition.stickiness = 'toNone';
 
-	const result = new OperationClass(
+	return new MoveOperation(
 		range.start,
 		range.end.offset - range.start.offset,
 		targetPosition,
-		0 // Is corrected anyway later.
+		0
 	);
-
-	return result;
 }

+ 2 - 3
packages/ckeditor5-engine/src/model/writer.js

@@ -12,7 +12,6 @@ import DetachOperation from './operation/detachoperation';
 import InsertOperation from './operation/insertoperation';
 import MarkerOperation from './operation/markeroperation';
 import MoveOperation from './operation/moveoperation';
-import RemoveOperation from './operation/removeoperation';
 import RenameOperation from './operation/renameoperation';
 import RootAttributeOperation from './operation/rootattributeoperation';
 import SplitOperation from './operation/splitoperation';
@@ -1330,7 +1329,7 @@ function applyMarkerOperation( writer, name, oldRange, newRange, affectsData ) {
 	model.applyOperation( operation );
 }
 
-// Creates `RemoveOperation` or `DetachOperation` that removes `howMany` nodes starting from `position`.
+// Creates `MoveOperation` or `DetachOperation` that removes `howMany` nodes starting from `position`.
 // The operation will be applied on given model instance and added to given operation instance.
 //
 // @private
@@ -1345,7 +1344,7 @@ function applyRemoveOperation( position, howMany, batch, model ) {
 		const doc = model.document;
 		const graveyardPosition = new Position( doc.graveyard, [ 0 ] );
 
-		operation = new RemoveOperation( position, howMany, graveyardPosition, doc.version );
+		operation = new MoveOperation( position, howMany, graveyardPosition, doc.version );
 	} else {
 		operation = new DetachOperation( position, howMany );
 	}

+ 2 - 3
packages/ckeditor5-engine/tests/dev-utils/enableenginedebug.js

@@ -21,7 +21,6 @@ import MoveOperation from '../../src/model/operation/moveoperation';
 import NoOperation from '../../src/model/operation/nooperation';
 import RenameOperation from '../../src/model/operation/renameoperation';
 import RootAttributeOperation from '../../src/model/operation/rootattributeoperation';
-import RemoveOperation from '../../src/model/operation/removeoperation';
 import transform from '../../src/model/operation/transform';
 import Model from '../../src/model/model';
 import ModelDocumentFragment from '../../src/model/documentfragment';
@@ -532,8 +531,8 @@ describe( 'debug tools', () => {
 				model.applyOperation( insert );
 
 				const graveyard = modelDoc.graveyard;
-				const remove = new RemoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( graveyard, 0 ), 1 );
-				model.applyOperation( remove );
+				const move = new MoveOperation( ModelPosition.createAt( modelRoot, 1 ), 2, ModelPosition.createAt( graveyard, 0 ), 1 );
+				model.applyOperation( move );
 			} );
 
 			log.resetHistory();

+ 1 - 2
packages/ckeditor5-engine/tests/model/differ.js

@@ -10,7 +10,6 @@ import Position from '../../src/model/position';
 import Range from '../../src/model/range';
 
 import InsertOperation from '../../src/model/operation/insertoperation';
-import RemoveOperation from '../../src/model/operation/removeoperation';
 import MoveOperation from '../../src/model/operation/moveoperation';
 import RenameOperation from '../../src/model/operation/renameoperation';
 import AttributeOperation from '../../src/model/operation/attributeoperation';
@@ -1617,7 +1616,7 @@ describe( 'Differ', () => {
 
 	function remove( sourcePosition, howMany ) {
 		const targetPosition = Position.createAt( doc.graveyard, doc.graveyard.maxOffset );
-		const operation = new RemoveOperation( sourcePosition, howMany, targetPosition, doc.version );
+		const operation = new MoveOperation( sourcePosition, howMany, targetPosition, doc.version );
 
 		model.applyOperation( operation );
 	}

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

@@ -13,7 +13,6 @@ import LiveRange from '../../src/model/liverange';
 import DocumentSelection from '../../src/model/documentselection';
 import InsertOperation from '../../src/model/operation/insertoperation';
 import MoveOperation from '../../src/model/operation/moveoperation';
-import RemoveOperation from '../../src/model/operation/removeoperation';
 import AttributeOperation from '../../src/model/operation/attributeoperation';
 import SplitOperation from '../../src/model/operation/splitoperation';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
@@ -1131,12 +1130,12 @@ describe( 'DocumentSelection', () => {
 			} );
 		} );
 
-		describe( 'RemoveOperation', () => {
+		describe( 'MoveOperation to graveyard', () => {
 			it( 'fix selection range if it ends up in graveyard #1', () => {
 				selection._setTo( new Position( root, [ 1, 3 ] ) );
 
 				model.applyOperation(
-					new RemoveOperation(
+					new MoveOperation(
 						new Position( root, [ 1, 2 ] ),
 						2,
 						new Position( doc.graveyard, [ 0 ] ),
@@ -1151,7 +1150,7 @@ describe( 'DocumentSelection', () => {
 				selection._setTo( [ new Range( new Position( root, [ 1, 2 ] ), new Position( root, [ 1, 4 ] ) ) ] );
 
 				model.applyOperation(
-					new RemoveOperation(
+					new MoveOperation(
 						new Position( root, [ 1, 2 ] ),
 						2,
 						new Position( doc.graveyard, [ 0 ] ),
@@ -1166,7 +1165,7 @@ describe( 'DocumentSelection', () => {
 				selection._setTo( [ new Range( new Position( root, [ 1, 1 ] ), new Position( root, [ 1, 2 ] ) ) ] );
 
 				model.applyOperation(
-					new RemoveOperation(
+					new MoveOperation(
 						new Position( root, [ 1 ] ),
 						2,
 						new Position( doc.graveyard, [ 0 ] ),
@@ -1179,7 +1178,7 @@ describe( 'DocumentSelection', () => {
 
 			it( 'fix selection range if it ends up in graveyard #4 - whole content removed', () => {
 				model.applyOperation(
-					new RemoveOperation(
+					new MoveOperation(
 						new Position( root, [ 0 ] ),
 						3,
 						new Position( doc.graveyard, [ 0 ] ),

+ 3 - 3
packages/ckeditor5-engine/tests/model/operation/insertoperation.js

@@ -7,7 +7,7 @@ import Model from '../../../src/model/model';
 import NodeList from '../../../src/model/nodelist';
 import Element from '../../../src/model/element';
 import InsertOperation from '../../../src/model/operation/insertoperation';
-import RemoveOperation from '../../../src/model/operation/removeoperation';
+import MoveOperation from '../../../src/model/operation/moveoperation';
 import Position from '../../../src/model/position';
 import Text from '../../../src/model/text';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
@@ -107,7 +107,7 @@ describe( 'InsertOperation', () => {
 		expect( root.getChild( 0 ).data ).to.equal( 'fooxbar' );
 	} );
 
-	it( 'should create a RemoveOperation as a reverse', () => {
+	it( 'should create a MoveOperation as a reverse', () => {
 		const position = new Position( root, [ 0 ] );
 		const operation = new InsertOperation(
 			position,
@@ -117,7 +117,7 @@ describe( 'InsertOperation', () => {
 
 		const reverse = operation.getReversed();
 
-		expect( reverse ).to.be.an.instanceof( RemoveOperation );
+		expect( reverse ).to.be.an.instanceof( MoveOperation );
 		expect( reverse.baseVersion ).to.equal( 1 );
 		expect( reverse.sourcePosition.isEqual( position ) ).to.be.true;
 		expect( reverse.howMany ).to.equal( 7 );

+ 12 - 8
packages/ckeditor5-engine/tests/model/operation/moveoperation.js

@@ -12,23 +12,27 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import { jsonParseStringify } from '../../../tests/model/_utils/utils';
 
 describe( 'MoveOperation', () => {
-	let model, doc, root;
+	let model, doc, root, gy;
 
 	beforeEach( () => {
 		model = new Model();
 		doc = model.document;
 		root = doc.createRoot();
+		gy = doc.graveyard;
 	} );
 
 	it( 'should have proper type', () => {
-		const op = new MoveOperation(
-			new Position( root, [ 0, 0 ] ),
-			1,
-			new Position( root, [ 1, 0 ] ),
-			doc.version
-		);
+		const move = new MoveOperation( new Position( root, [ 0, 0 ] ), 1, new Position( root, [ 1, 0 ] ), 0 );
+		expect( move.type ).to.equal( 'move' );
+
+		const remove1 = new MoveOperation( new Position( root, [ 0, 0 ] ), 1, new Position( gy, [ 0 ] ), 0 );
+		expect( remove1.type ).to.equal( 'remove' );
+
+		const remove2 = new MoveOperation( new Position( gy, [ 0 ] ), 1, new Position( gy, [ 1 ] ), 0 );
+		expect( remove2.type ).to.equal( 'remove' );
 
-		expect( op.type ).to.equal( 'move' );
+		const reinsert = new MoveOperation( new Position( gy, [ 0 ] ), 1, new Position( root, [ 0, 0 ] ), 0 );
+		expect( reinsert.type ).to.equal( 'reinsert' );
 	} );
 
 	it( 'should move from one node to another', () => {

+ 0 - 157
packages/ckeditor5-engine/tests/model/operation/reinsertoperation.js

@@ -1,157 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-import Model from '../../../src/model/model';
-import ReinsertOperation from '../../../src/model/operation/reinsertoperation';
-import RemoveOperation from '../../../src/model/operation/removeoperation';
-import MoveOperation from '../../../src/model/operation/moveoperation';
-import Position from '../../../src/model/position';
-import DocumentFragment from '../../../src/model/documentfragment';
-import Element from '../../../src/model/element';
-import Text from '../../../src/model/text';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
-import { jsonParseStringify } from '../../../tests/model/_utils/utils';
-
-describe( 'ReinsertOperation', () => {
-	let model, doc, root, graveyard, operation, graveyardPosition, rootPosition;
-
-	beforeEach( () => {
-		model = new Model();
-		doc = model.document;
-		root = doc.createRoot();
-		graveyard = doc.graveyard;
-
-		graveyardPosition = new Position( graveyard, [ 0 ] );
-		rootPosition = new Position( root, [ 0 ] );
-
-		operation = new ReinsertOperation(
-			graveyardPosition,
-			2,
-			rootPosition,
-			doc.version
-		);
-	} );
-
-	it( 'should have position property equal to the position where node will be reinserted', () => {
-		expect( operation.position.isEqual( rootPosition ) ).to.be.true;
-
-		// Setting also works:
-		operation.position = new Position( root, [ 1 ] );
-		expect( operation.position.isEqual( new Position( root, [ 1 ] ) ) ).to.be.true;
-	} );
-
-	it( 'should have proper type', () => {
-		expect( operation.type ).to.equal( 'reinsert' );
-	} );
-
-	it( 'should extend MoveOperation class', () => {
-		expect( operation ).to.be.instanceof( MoveOperation );
-	} );
-
-	it( 'should create ReinsertOperation with same parameters when cloned', () => {
-		const clone = operation.clone();
-
-		expect( clone ).to.be.instanceof( ReinsertOperation );
-		expect( clone.sourcePosition.isEqual( operation.sourcePosition ) ).to.be.true;
-		expect( clone.targetPosition.isEqual( operation.targetPosition ) ).to.be.true;
-		expect( clone.howMany ).to.equal( operation.howMany );
-		expect( clone.baseVersion ).to.equal( operation.baseVersion );
-	} );
-
-	it( 'should create RemoveOperation as a reverse', () => {
-		graveyard._appendChild( new Element( 'x' ) );
-
-		const reverse = operation.getReversed();
-
-		expect( reverse ).to.be.an.instanceof( RemoveOperation );
-		expect( reverse.baseVersion ).to.equal( 1 );
-		expect( reverse.howMany ).to.equal( 2 );
-		expect( reverse.sourcePosition.isEqual( rootPosition ) ).to.be.true;
-		expect( reverse.targetPosition.isEqual( graveyardPosition ) ).to.be.true;
-	} );
-
-	it( 'should create correct RemoveOperation when reversed if target position was in graveyard', () => {
-		const operation = new ReinsertOperation( new Position( doc.graveyard, [ 0 ] ), 1, new Position( doc.graveyard, [ 3 ] ), 0 );
-		const reverse = operation.getReversed();
-
-		expect( reverse.sourcePosition.path ).to.deep.equal( [ 2 ] );
-		expect( reverse.targetPosition.path ).to.deep.equal( [ 0 ] );
-	} );
-
-	it( 'should undo reinsert set of nodes by applying reverse operation', () => {
-		const reverse = operation.getReversed();
-
-		graveyard._insertChild( 0, new Text( 'xx' ) );
-
-		model.applyOperation( operation );
-
-		expect( doc.version ).to.equal( 1 );
-		expect( root.maxOffset ).to.equal( 2 );
-		expect( graveyard.maxOffset ).to.equal( 0 );
-
-		model.applyOperation( reverse );
-
-		expect( doc.version ).to.equal( 2 );
-		expect( root.maxOffset ).to.equal( 0 );
-		expect( graveyard.maxOffset ).to.equal( 2 );
-	} );
-
-	describe( '_validate()', () => {
-		it( 'should throw when target position is not in the document', () => {
-			const docFrag = new DocumentFragment();
-
-			graveyard._insertChild( 0, new Text( 'xx' ) );
-
-			operation = new ReinsertOperation(
-				graveyardPosition,
-				1,
-				Position.createAt( docFrag ),
-				doc.version
-			);
-
-			expect( () => {
-				operation._validate();
-			} ).to.throw( CKEditorError, /^reinsert-operation-to-detached-parent/ );
-		} );
-
-		it( 'should throw when source position is not in the document', () => {
-			const docFrag = new DocumentFragment( new Text( 'xx' ) );
-
-			operation = new ReinsertOperation(
-				Position.createAt( docFrag ),
-				1,
-				rootPosition,
-				doc.version
-			);
-
-			expect( () => {
-				operation._validate();
-			} ).to.throw( CKEditorError, /^reinsert-operation-on-detached-item/ );
-		} );
-	} );
-
-	describe( 'toJSON', () => {
-		it( 'should create proper json object', () => {
-			const serialized = jsonParseStringify( operation );
-
-			expect( serialized ).to.deep.equal( {
-				__className: 'engine.model.operation.ReinsertOperation',
-				baseVersion: 0,
-				howMany: 2,
-				sourcePosition: jsonParseStringify( operation.sourcePosition ),
-				targetPosition: jsonParseStringify( operation.targetPosition )
-			} );
-		} );
-	} );
-
-	describe( 'fromJSON', () => {
-		it( 'should create proper ReinsertOperation from json object', () => {
-			const serialized = jsonParseStringify( operation );
-			const deserialized = ReinsertOperation.fromJSON( serialized, doc );
-
-			expect( deserialized ).to.deep.equal( operation );
-		} );
-	} );
-} );

+ 0 - 191
packages/ckeditor5-engine/tests/model/operation/removeoperation.js

@@ -1,191 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-import Model from '../../../src/model/model';
-import ReinsertOperation from '../../../src/model/operation/reinsertoperation';
-import RemoveOperation from '../../../src/model/operation/removeoperation';
-import MoveOperation from '../../../src/model/operation/moveoperation';
-import Position from '../../../src/model/position';
-import DocumentFragment from '../../../src/model/documentfragment';
-import Element from '../../../src/model/element';
-import Text from '../../../src/model/text';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
-import { jsonParseStringify } from '../../../tests/model/_utils/utils';
-
-describe( 'RemoveOperation', () => {
-	let model, doc, root, graveyard;
-
-	beforeEach( () => {
-		model = new Model();
-		doc = model.document;
-		root = doc.createRoot();
-		graveyard = doc.graveyard;
-	} );
-
-	it( 'should have proper type', () => {
-		const op = new RemoveOperation(
-			new Position( root, [ 2 ] ),
-			2,
-			new Position( doc.graveyard, [ 0 ] ),
-			doc.version
-		);
-
-		expect( op.type ).to.equal( 'remove' );
-	} );
-
-	it( 'should extend MoveOperation class', () => {
-		const operation = new RemoveOperation(
-			new Position( root, [ 2 ] ),
-			2,
-			new Position( doc.graveyard, [ 0 ] ),
-			doc.version
-		);
-
-		expect( operation ).to.be.instanceof( MoveOperation );
-	} );
-
-	it( 'should be able to remove set of nodes and append them to graveyard root', () => {
-		root._insertChild( 0, new Text( 'fozbar' ) );
-
-		model.applyOperation(
-			new RemoveOperation(
-				new Position( root, [ 2 ] ),
-				2,
-				new Position( doc.graveyard, [ 0 ] ),
-				doc.version
-			)
-		);
-
-		expect( doc.version ).to.equal( 1 );
-		expect( root.maxOffset ).to.equal( 4 );
-		expect( root.getChild( 0 ).data ).to.equal( 'foar' );
-
-		expect( graveyard.maxOffset ).to.equal( 2 );
-		expect( graveyard.getChild( 0 ).data ).to.equal( 'zb' );
-	} );
-
-	it( 'should create RemoveOperation with same parameters when cloned', () => {
-		const pos = new Position( root, [ 2 ] );
-
-		const operation = new RemoveOperation( pos, 2, new Position( doc.graveyard, [ 0 ] ), doc.version );
-		const clone = operation.clone();
-
-		expect( clone ).to.be.instanceof( RemoveOperation );
-		expect( clone.sourcePosition.isEqual( pos ) ).to.be.true;
-		expect( clone.targetPosition.isEqual( operation.targetPosition ) ).to.be.true;
-		expect( clone.howMany ).to.equal( operation.howMany );
-		expect( clone.baseVersion ).to.equal( operation.baseVersion );
-	} );
-
-	it( 'should create ReinsertOperation when reversed', () => {
-		const position = new Position( root, [ 0 ] );
-		const operation = new RemoveOperation( position, 2, new Position( doc.graveyard, [ 0 ] ), 0 );
-		const reverse = operation.getReversed();
-
-		expect( reverse ).to.be.an.instanceof( ReinsertOperation );
-		expect( reverse.baseVersion ).to.equal( 1 );
-		expect( reverse.howMany ).to.equal( 2 );
-		expect( reverse.sourcePosition.isEqual( operation.targetPosition ) ).to.be.true;
-		expect( reverse.targetPosition.isEqual( position ) ).to.be.true;
-	} );
-
-	it( 'should create correct ReinsertOperation when reversed if source range was in graveyard', () => {
-		const operation = new RemoveOperation( new Position( doc.graveyard, [ 2 ] ), 1, new Position( doc.graveyard, [ 0 ] ), 0 );
-		const reverse = operation.getReversed();
-
-		expect( reverse.sourcePosition.path ).to.deep.equal( [ 0 ] );
-		expect( reverse.targetPosition.path ).to.deep.equal( [ 3 ] );
-	} );
-
-	it( 'should undo remove set of nodes by applying reverse operation', () => {
-		const position = new Position( root, [ 0 ] );
-		const operation = new RemoveOperation( position, 3, new Position( doc.graveyard, [ 0 ] ), 0 );
-		const reverse = operation.getReversed();
-
-		root._insertChild( 0, new Text( 'bar' ) );
-
-		model.applyOperation( operation );
-
-		expect( doc.version ).to.equal( 1 );
-		expect( root.maxOffset ).to.equal( 0 );
-
-		model.applyOperation( reverse );
-
-		expect( doc.version ).to.equal( 2 );
-		expect( root.maxOffset ).to.equal( 3 );
-		expect( root.getChild( 0 ).data ).to.equal( 'bar' );
-	} );
-
-	it( 'should properly remove a node that is already in a graveyard', () => {
-		doc.graveyard._appendChild( [ new Element( 'x' ), new Element( 'y' ), new Element( 'z' ) ] );
-
-		const position = new Position( doc.graveyard, [ 2 ] );
-		const operation = new RemoveOperation( position, 1, new Position( doc.graveyard, [ 0 ] ), 0 );
-
-		model.applyOperation( operation );
-
-		expect( doc.graveyard.childCount ).to.equal( 3 );
-		expect( doc.graveyard.getChild( 0 ).name ).to.equal( 'z' );
-		expect( doc.graveyard.getChild( 1 ).name ).to.equal( 'x' );
-		expect( doc.graveyard.getChild( 2 ).name ).to.equal( 'y' );
-	} );
-
-	describe( '_validate()', () => {
-		it( 'should throw when is executed on detached item', () => {
-			const docFrag = new DocumentFragment();
-			const item = new Element( 'foo' );
-
-			docFrag._appendChild( [ item ] );
-
-			const op = new RemoveOperation(
-				new Position( docFrag, [ 0 ] ),
-				1,
-				new Position( doc.graveyard, [ 0 ] ),
-				doc.version
-			);
-
-			expect( () => {
-				op._validate();
-			} ).to.throw( CKEditorError, /^remove-operation-on-detached-item/ );
-		} );
-	} );
-
-	describe( 'toJSON', () => {
-		it( 'should create proper json object', () => {
-			const op = new RemoveOperation(
-				new Position( root, [ 2 ] ),
-				2,
-				new Position( doc.graveyard, [ 0 ] ),
-				doc.version
-			);
-
-			const serialized = jsonParseStringify( op );
-
-			expect( serialized ).to.deep.equal( {
-				__className: 'engine.model.operation.RemoveOperation',
-				baseVersion: 0,
-				howMany: 2,
-				sourcePosition: jsonParseStringify( op.sourcePosition ),
-				targetPosition: jsonParseStringify( op.targetPosition )
-			} );
-		} );
-	} );
-
-	describe( 'fromJSON', () => {
-		it( 'should create proper RemoveOperation from json object', () => {
-			const op = new RemoveOperation(
-				new Position( root, [ 2 ] ),
-				2,
-				new Position( doc.graveyard, [ 0 ] ),
-				doc.version
-			);
-
-			const serialized = jsonParseStringify( op );
-			const deserialized = RemoveOperation.fromJSON( serialized, doc );
-
-			expect( deserialized ).to.deep.equal( op );
-		} );
-	} );
-} );

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

@@ -16,7 +16,6 @@ import AttributeOperation from '../../../src/model/operation/attributeoperation'
 import RootAttributeOperation from '../../../src/model/operation/rootattributeoperation';
 import MarkerOperation from '../../../src/model/operation/markeroperation';
 import MoveOperation from '../../../src/model/operation/moveoperation';
-import RemoveOperation from '../../../src/model/operation/removeoperation';
 import RenameOperation from '../../../src/model/operation/renameoperation';
 import NoOperation from '../../../src/model/operation/nooperation';
 
@@ -688,7 +687,7 @@ describe( 'transform', () => {
 			} );
 		} );
 
-		describe( 'by RemoveOperation', () => {
+		describe( 'by MoveOperation to graveyard', () => {
 			beforeEach( () => {
 				start = new Position( doc.graveyard, [ 2, 0 ] );
 				end = new Position( doc.graveyard, [ 2, 4 ] );
@@ -701,7 +700,7 @@ describe( 'transform', () => {
 			} );
 
 			it( 'remove operation inserted elements before attribute operation range: increment path', () => {
-				const transformBy = new RemoveOperation(
+				const transformBy = new MoveOperation(
 					new Position( root, [ 0 ] ),
 					2,
 					new Position( doc.graveyard, [ 0 ] ),
@@ -721,7 +720,7 @@ describe( 'transform', () => {
 			} );
 
 			it( 'remove operation inserted elements after attribute operation range: do nothing', () => {
-				const transformBy = new RemoveOperation(
+				const transformBy = new MoveOperation(
 					new Position( root, [ 0 ] ),
 					2,
 					new Position( doc.graveyard, [ 0 ] ),
@@ -1962,11 +1961,11 @@ describe( 'transform', () => {
 			} );
 		} );
 
-		describe( 'by RemoveOperation', () => {
+		describe( 'by MoveOperation to graveyard', () => {
 			let transformBy;
 
 			beforeEach( () => {
-				transformBy = new RemoveOperation(
+				transformBy = new MoveOperation(
 					Position.createFromPosition( op.sourcePosition ),
 					op.howMany,
 					new Position( doc.graveyard, [ 0 ] ),
@@ -1974,7 +1973,7 @@ describe( 'transform', () => {
 				);
 			} );
 
-			it( 'should skip context.aIsStrong and be less important than RemoveOperation', () => {
+			it( 'should skip context.aIsStrong and be less important than MoveOperation', () => {
 				const transOp = transform.transform( op, transformBy, { aIsStrong: true } );
 
 				expect( transOp.length ).to.equal( 1 );
@@ -2020,10 +2019,10 @@ describe( 'transform', () => {
 		} );
 	} );
 
-	describe( 'RemoveOperation', () => {
+	describe( 'MoveOperation to graveyard', () => {
 		describe( 'by MoveOperation', () => {
 			it( 'should force removing content even if was less important', () => {
-				const op = new RemoveOperation( new Position( root, [ 8 ] ), 2, new Position( doc.graveyard, [ 0 ] ), 0 );
+				const op = new MoveOperation( new Position( root, [ 8 ] ), 2, new Position( doc.graveyard, [ 0 ] ), 0 );
 
 				const targetPosition = Position.createFromPosition( op.targetPosition );
 
@@ -2036,7 +2035,7 @@ describe( 'transform', () => {
 				expect( transOp.length ).to.equal( 1 );
 
 				expectOperation( transOp[ 0 ], {
-					type: RemoveOperation,
+					type: MoveOperation,
 					howMany: 2,
 					sourcePosition,
 					targetPosition

+ 4 - 5
packages/ckeditor5-engine/tests/model/range.js

@@ -12,7 +12,6 @@ import TreeWalker from '../../src/model/treewalker';
 import AttributeOperation from '../../src/model/operation/attributeoperation';
 import InsertOperation from '../../src/model/operation/insertoperation';
 import MoveOperation from '../../src/model/operation/moveoperation';
-import RemoveOperation from '../../src/model/operation/removeoperation';
 import RenameOperation from '../../src/model/operation/renameoperation';
 import MergeOperation from '../../src/model/operation/mergeoperation';
 import SplitOperation from '../../src/model/operation/splitoperation';
@@ -898,10 +897,10 @@ describe( 'Range', () => {
 			} );
 		} );
 
-		describe( 'by RemoveOperation', () => {
+		describe( 'by MoveOperation to graveyard', () => {
 			it( 'remove before range', () => {
 				const start = new Position( root, [ 0 ] );
-				const op = new RemoveOperation( start, 2, gyPos, 1 );
+				const op = new MoveOperation( start, 2, gyPos, 1 );
 
 				const transformed = range.getTransformedByOperation( op );
 
@@ -910,7 +909,7 @@ describe( 'Range', () => {
 
 			it( 'remove intersecting with range', () => {
 				const start = new Position( root, [ 4 ] );
-				const op = new RemoveOperation( start, 2, gyPos, 1 );
+				const op = new MoveOperation( start, 2, gyPos, 1 );
 
 				const transformed = range.getTransformedByOperation( op );
 
@@ -922,7 +921,7 @@ describe( 'Range', () => {
 			it( 'remove inside the range', () => {
 				const start = new Position( root, [ 3 ] );
 
-				const op = new RemoveOperation( start, 2, gyPos, 1 );
+				const op = new MoveOperation( start, 2, gyPos, 1 );
 
 				const transformed = range.getTransformedByOperation( op );
 

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

@@ -1545,7 +1545,7 @@ describe( 'Writer', () => {
 				expect( batch.operations.length ).to.equal( 2 );
 			} );
 
-			it( 'should use RemoveOperation', () => {
+			it( 'should use MoveOperation to graveyard', () => {
 				batch = new Batch();
 				remove( div );