浏览代码

Fixed: Remove by remove change transformation in Differ was incorrect.

Szymon Cofalik 7 年之前
父节点
当前提交
94c7224549
共有 2 个文件被更改,包括 20 次插入5 次删除
  1. 3 5
      packages/ckeditor5-engine/src/model/differ.js
  2. 17 0
      packages/ckeditor5-engine/tests/model/differ.js

+ 3 - 5
packages/ckeditor5-engine/src/model/differ.js

@@ -645,13 +645,11 @@ export default class Differ {
 				}
 
 				if ( old.type == 'remove' ) {
-					if ( inc.offset + inc.howMany <= old.offset ) {
+					if ( incEnd <= old.offset ) {
 						old.offset -= inc.howMany;
 					} else if ( inc.offset < old.offset ) {
-						old.offset = inc.offset;
-						old.howMany += inc.nodesToHandle;
-
-						inc.nodesToHandle = 0;
+						inc.nodesToHandle += old.howMany;
+						old.howMany = 0;
 					}
 				}
 

+ 17 - 0
packages/ckeditor5-engine/tests/model/differ.js

@@ -1321,6 +1321,23 @@ describe( 'Differ', () => {
 				] );
 			} );
 		} );
+
+		// #1392.
+		it( 'remove is correctly transformed by multiple affecting changes', () => {
+			root._appendChildren( new Element( 'paragraph', null, new Text( 'xyz' ) ) );
+
+			model.change( () => {
+				rename( root.getChild( 1 ), 'heading' );
+				rename( root.getChild( 2 ), 'heading' );
+				remove( Position.createAt( root, 0 ), 3 );
+
+				expectChanges( [
+					{ type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 0 ] ) },
+					{ type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 0 ] ) },
+					{ type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 0 ] ) }
+				] );
+			} );
+		} );
 	} );
 
 	describe( 'getChanges()', () => {