8
0
Эх сурвалжийг харах

MoveOperation child-classes return instances of proper class when cloned.

Szymon Cofalik 10 жил өмнө
parent
commit
6b4b7119b6

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

@@ -56,11 +56,11 @@ CKEDITOR.define( [
 		}
 
 		clone() {
-			return new MoveOperation( this.sourcePosition.clone(), this.howMany, this.targetPosition.clone(), this.baseVersion );
+			return new this.constructor( this.sourcePosition.clone(), this.howMany, this.targetPosition.clone(), this.baseVersion );
 		}
 
 		getReversed() {
-			return new MoveOperation( this.targetPosition.clone(), this.howMany, this.sourcePosition.clone(), this.baseVersion + 1 );
+			return new this.constructor( this.targetPosition.clone(), this.howMany, this.sourcePosition.clone(), this.baseVersion + 1 );
 		}
 
 		_execute() {

+ 4 - 0
packages/ckeditor5-engine/src/treemodel/operation/removeoperation.js

@@ -41,6 +41,10 @@ CKEDITOR.define( [
 
 			return new ReinsertOperation( this.targetPosition, this.howMany, this.sourcePosition, this.baseVersion + 1 );
 		}
+
+		clone() {
+			return new RemoveOperation( this.sourcePosition, this.howMany, this.baseVersion );
+		}
 	}
 
 	return RemoveOperation;

+ 1 - 1
packages/ckeditor5-engine/tests/treemodel/operation/moveoperation.js

@@ -239,7 +239,7 @@ describe( 'MoveOperation', () => {
 		expect( p.getChild( 0 ).character ).to.equal( 'b' );
 	} );
 
-	it( 'should create operation with the same parameters when cloned', () => {
+	it( 'should create MoveOperation with the same parameters when cloned', () => {
 		let sourcePosition = new Position( root, [ 0 ] );
 		let targetPosition = new Position( root, [ 1 ] );
 		let howMany = 4;

+ 10 - 0
packages/ckeditor5-engine/tests/treemodel/operation/reinsertoperation.js

@@ -52,6 +52,16 @@ describe( 'ReinsertOperation', () => {
 		expect( operation ).to.be.instanceof( MoveOperation );
 	} );
 
+	it( 'should create ReinsertOperation with same parameters when cloned', () => {
+		let 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 a remove operation as a reverse', () => {
 		let reverse = operation.getReversed();
 

+ 12 - 0
packages/ckeditor5-engine/tests/treemodel/operation/removeoperation.js

@@ -78,6 +78,18 @@ describe( 'RemoveOperation', () => {
 		expect( graveyard.getChild( 1 ) ).to.equal( b );
 	} );
 
+	it( 'should create RemoveOperation with same parameters when cloned', () => {
+		let pos = new Position( root, [ 2 ] );
+
+		let operation = new RemoveOperation( pos, 2, doc.version );
+		let clone = operation.clone();
+
+		expect( clone ).to.be.instanceof( RemoveOperation );
+		expect( clone.sourcePosition.isEqual( pos ) ).to.be.true;
+		expect( clone.howMany ).to.equal( operation.howMany );
+		expect( clone.baseVersion ).to.equal( operation.baseVersion );
+	} );
+
 	it( 'should create a reinsert operation as a reverse', () => {
 		let position = new Position( root, [ 0 ] );
 		let operation = new RemoveOperation( position, 2, 0 );