8
0
Pārlūkot izejas kodu

Added another case for checking if range is moved to the same position.

Oskar Wróbel 6 gadi atpakaļ
vecāks
revīzija
e88b80c311

+ 4 - 1
packages/ckeditor5-engine/src/model/differ.js

@@ -151,7 +151,10 @@ export default class Differ {
 			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 ) ) {
+				if (
+					operation.sourcePosition.isEqual( operation.targetPosition ) ||
+					operation.sourcePosition.getShiftedBy( operation.howMany ).isEqual( operation.targetPosition )
+				) {
 					return;
 				}
 

+ 22 - 1
packages/ckeditor5-engine/tests/model/differ.js

@@ -631,7 +631,7 @@ describe( 'Differ', () => {
 		} );
 
 		// https://github.com/ckeditor/ckeditor5-engine/issues/1664
-		it( 'move to the same position', () => {
+		it( 'move to the same position #1', () => {
 			const position = new Position( root, [ 0 ] );
 
 			model.change( () => {
@@ -640,6 +640,27 @@ describe( 'Differ', () => {
 				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 ] );
+
+			root._appendChild( [
+				new Element( 'paragraph', null, [
+					new Text( 'x' )
+				] ),
+				new Element( 'paragraph', null, [
+					new Text( 'y' )
+				] )
+			] );
+
+			model.change( () => {
+				move( sourcePosition, 2, targetPosition );
+
+				expectChanges( [] );
+			} );
+		} );
 	} );
 
 	describe( 'rename', () => {