Browse Source

Fixed: `SplitDelta#_moveOperation` should return null if second operation is `NoOperation`.

Szymon Cofalik 8 years ago
parent
commit
612e5501f3

+ 1 - 1
packages/ckeditor5-engine/src/model/delta/splitdelta.js

@@ -66,7 +66,7 @@ export default class SplitDelta extends Delta {
 	 * @type {module:engine/model/operation/moveoperation~MoveOperation|null}
 	 */
 	get _moveOperation() {
-		return this.operations[ 1 ] || null;
+		return this.operations[ 1 ] && this.operations[ 1 ] instanceof MoveOperation ? this.operations[ 1 ] : null;
 	}
 
 	/**

+ 27 - 4
packages/ckeditor5-engine/tests/model/delta/splitdelta.js

@@ -14,6 +14,7 @@ import SplitDelta from '../../../src/model/delta/splitdelta';
 
 import InsertOperation from '../../../src/model/operation/insertoperation';
 import MoveOperation from '../../../src/model/operation/moveoperation';
+import NoOperation from '../../../src/model/operation/nooperation';
 import RemoveOperation from '../../../src/model/operation/removeoperation';
 
 import count from '@ckeditor/ckeditor5-utils/src/count';
@@ -162,12 +163,34 @@ describe( 'SplitDelta', () => {
 
 		it( 'should return the first operation in the delta, which is InsertOperation or ReinsertOperation', () => {
 			const p = new Element( 'p' );
-			splitDelta.operations.push( new InsertOperation( new Position( root, [ 1, 2 ] ), p, 0 ) );
+			const insert = new InsertOperation( new Position( root, [ 1, 2 ] ), p, 0 );
+			splitDelta.operations.push( insert );
 			splitDelta.operations.push( new MoveOperation( new Position( root, [ 1, 1, 4 ] ), 4, new Position( root, [ 1, 2, 0 ] ), 1 ) );
 
-			expect( splitDelta._cloneOperation ).to.be.instanceof( InsertOperation );
-			expect( splitDelta._cloneOperation.nodes.getNode( 0 ) ).to.equal( p );
-			expect( splitDelta._cloneOperation.position.path ).to.deep.equal( [ 1, 2 ] );
+			expect( splitDelta._cloneOperation ).to.equal( insert );
+		} );
+	} );
+
+	describe( '_moveOperation', () => {
+		it( 'should return null if delta has no operations', () => {
+			expect( splitDelta._moveOperation ).to.be.null;
+		} );
+
+		it( 'should return null if second operation is NoOperation', () => {
+			const p = new Element( 'p' );
+			splitDelta.operations.push( new InsertOperation( new Position( root, [ 1, 2 ] ), p, 0 ) );
+			splitDelta.operations.push( new NoOperation( 1 ) );
+
+			expect( splitDelta._moveOperation ).to.be.null;
+		} );
+
+		it( 'should return second operation if it is MoveOperation', () => {
+			const p = new Element( 'p' );
+			const move = new MoveOperation( new Position( root, [ 1, 1, 4 ] ), 4, new Position( root, [ 1, 2, 0 ] ), 1 );
+			splitDelta.operations.push( new InsertOperation( new Position( root, [ 1, 2 ] ), p, 0 ) );
+			splitDelta.operations.push( move );
+
+			expect( splitDelta._moveOperation ).to.equal( move );
 		} );
 	} );