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

Fixed: InsertOperation should copy its nodes when it's cloned.

Szymon Cofalik 9 лет назад
Родитель
Сommit
131f8b5e09

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

@@ -58,7 +58,9 @@ export default class InsertOperation extends Operation {
 	 * @returns {engine.model.operation.InsertOperation}
 	 */
 	clone() {
-		return new InsertOperation( this.position, this.nodes, this.baseVersion );
+		const nodes = new NodeList( [ ...this.nodes ].map( ( node ) => node.clone( true ) ) );
+
+		return new InsertOperation( this.position, nodes, this.baseVersion );
 	}
 
 	/**

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

@@ -177,8 +177,13 @@ describe( 'InsertOperation', () => {
 
 		expect( clone ).to.be.instanceof( InsertOperation );
 		expect( clone.position.isEqual( position ) ).to.be.true;
-		expect( clone.nodes.getNode( 0 ) ).to.equal( nodeA );
-		expect( clone.nodes.getNode( 1 ) ).to.equal( nodeB );
+
+		// New node, not pointer to the old instance.
+		expect( clone.nodes.getNode( 0 ) ).not.to.equal( nodeA );
+		expect( clone.nodes.getNode( 1 ) ).not.to.equal( nodeB );
+		expect( clone.nodes.getNode( 0 ) ).to.deep.equal( nodeA );
+		expect( clone.nodes.getNode( 1 ) ).to.deep.equal( nodeB );
+
 		expect( clone.nodes.length ).to.equal( 2 );
 		expect( clone.baseVersion ).to.equal( baseVersion );
 	} );