浏览代码

Fixed: Prevent errors in AttributeDelta if one of operations is NoOperation.

Szymon Cofalik 8 年之前
父节点
当前提交
c68ce8637e

+ 5 - 0
packages/ckeditor5-engine/src/model/delta/attributedelta.js

@@ -12,6 +12,7 @@ import DeltaFactory from './deltafactory';
 import { register } from '../batch';
 import AttributeOperation from '../operation/attributeoperation';
 import RootAttributeOperation from '../operation/rootattributeoperation';
+import NoOperation from '../operation/nooperation';
 import Position from '../position';
 import Range from '../range';
 
@@ -65,6 +66,10 @@ export default class AttributeDelta extends Delta {
 		let end = null;
 
 		for ( const operation of this.operations ) {
+			if ( operation instanceof NoOperation ) {
+				continue;
+			}
+
 			if ( start === null || start.isAfter( operation.range.start ) ) {
 				start = operation.range.start;
 			}

+ 13 - 0
packages/ckeditor5-engine/tests/model/delta/attributedelta.js

@@ -11,6 +11,7 @@ import Position from '../../../src/model/position';
 import Element from '../../../src/model/element';
 import { default as AttributeDelta, RootAttributeDelta } from '../../../src/model/delta/attributedelta';
 import AttributeOperation from '../../../src/model/operation/attributeoperation';
+import NoOperation from '../../../src/model/operation/nooperation';
 import { jsonParseStringify } from '../../../tests/model/_utils/utils';
 
 describe( 'Batch', () => {
@@ -466,6 +467,18 @@ describe( 'AttributeDelta', () => {
 			expect( delta.range.start.path ).to.deep.equal( [ 1 ] );
 			expect( delta.range.end.path ).to.deep.equal( [ 6 ] );
 		} );
+
+		it( 'should return correct values when some operations are NoOperations', () => {
+			const rangeA = new Range( new Position( root, [ 2 ] ), new Position( root, [ 4 ] ) );
+			const rangeB = new Range( new Position( root, [ 5 ] ), new Position( root, [ 6 ] ) );
+
+			delta.addOperation( new AttributeOperation( rangeA, 'key', 'oldA', 'new', 0 ) );
+			delta.addOperation( new NoOperation( 1 ) );
+			delta.addOperation( new AttributeOperation( rangeB, 'key', 'oldC', 'new', 2 ) );
+
+			expect( delta.range.start.path ).to.deep.equal( [ 2 ] );
+			expect( delta.range.end.path ).to.deep.equal( [ 6 ] );
+		} );
 	} );
 
 	describe( 'getReversed', () => {