瀏覽代碼

Merge pull request #1666 from ckeditor/t/1664

Fix: Moving to the same position is not handled by the Differ as a change
Kacper Tomporowski 6 年之前
父節點
當前提交
ce3a07d714
共有 2 個文件被更改,包括 38 次插入0 次删除
  1. 9 0
      packages/ckeditor5-engine/src/model/differ.js
  2. 29 0
      packages/ckeditor5-engine/tests/model/differ.js

+ 9 - 0
packages/ckeditor5-engine/src/model/differ.js

@@ -149,6 +149,15 @@ export default class Differ {
 			case 'remove':
 			case 'move':
 			case 'reinsert': {
+				// When range is moved to the same position then not mark it as a change.
+				// See: https://github.com/ckeditor/ckeditor5-engine/issues/1664.
+				if (
+					operation.sourcePosition.isEqual( operation.targetPosition ) ||
+					operation.sourcePosition.getShiftedBy( operation.howMany ).isEqual( operation.targetPosition )
+				) {
+					return;
+				}
+
 				const sourceParentInserted = this._isInInsertedElement( operation.sourcePosition.parent );
 				const targetParentInserted = this._isInInsertedElement( operation.targetPosition.parent );
 

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

@@ -629,6 +629,35 @@ describe( 'Differ', () => {
 				] );
 			} );
 		} );
+
+		// https://github.com/ckeditor/ckeditor5-engine/issues/1664
+		it( 'move to the same position #1', () => {
+			const position = new Position( root, [ 0 ] );
+
+			model.change( () => {
+				move( position, 1, position );
+
+				expectChanges( [] );
+			} );
+		} );
+
+		// https://github.com/ckeditor/ckeditor5-engine/issues/1664
+		it( 'move to the same position #2', () => {
+			const sourcePosition = new Position( root, [ 0 ] );
+			const targetPosition = new Position( root, [ 2 ] );
+
+			// Add two more elements to the root, now there are 4 paragraphs.
+			root._appendChild( [
+				new Element( 'paragraph' ),
+				new Element( 'paragraph' )
+			] );
+
+			model.change( () => {
+				move( sourcePosition, 2, targetPosition );
+
+				expectChanges( [] );
+			} );
+		} );
 	} );
 
 	describe( 'rename', () => {