Explorar el Código

Merge pull request #414 from ckeditor/t/413

Fixed: MoveOperation thrown errors when it should not (fixes #413).
Piotrek Koszuliński hace 9 años
padre
commit
c91e9c41ae

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

@@ -139,7 +139,7 @@ export default class MoveOperation extends Operation {
 			throw new CKEditorError(
 				'operation-move-range-into-itself: Trying to move a range of nodes to the inside of that range.'
 			);
-		} else {
+		} else if ( this.sourcePosition.root == this.targetPosition.root ) {
 			if ( compareArrays( this.sourcePosition.getParentPath(), this.targetPosition.getParentPath() ) == 'PREFIX' ) {
 				let i = this.sourcePosition.path.length - 1;
 

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

@@ -238,6 +238,25 @@ describe( 'MoveOperation', () => {
 		expect( p.getChild( 0 ).character ).to.equal( 'b' );
 	} );
 
+	it( 'should not throw when operation paths looks like incorrect but move is between different roots', () => {
+		let p = new Element( 'p' );
+		root.insertChildren( 0, [ 'a', p, 'b' ] );
+		doc.graveyard.insertChildren( 0, [ 'abc' ] );
+
+		let operation = new MoveOperation(
+			new Position( doc.graveyard, [ 0 ] ),
+			2,
+			new Position( root, [ 1, 0 ] ),
+			doc.version
+		);
+
+		expect(
+			() => {
+				doc.applyOperation( operation );
+			}
+		).not.to.throw();
+	} );
+
 	it( 'should create MoveOperation with the same parameters when cloned', () => {
 		let sourcePosition = new Position( root, [ 0 ] );
 		let targetPosition = new Position( root, [ 1 ] );