Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 7dfaae6

Browse files
authored
Merge pull request #1666 from ckeditor/t/1664
Fix: Moving to the same position is not handled by the Differ as a change
2 parents fcc821f + df79eb7 commit 7dfaae6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/model/differ.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ export default class Differ {
149149
case 'remove':
150150
case 'move':
151151
case 'reinsert': {
152+
// When range is moved to the same position then not mark it as a change.
153+
// See: https://github.com/ckeditor/ckeditor5-engine/issues/1664.
154+
if (
155+
operation.sourcePosition.isEqual( operation.targetPosition ) ||
156+
operation.sourcePosition.getShiftedBy( operation.howMany ).isEqual( operation.targetPosition )
157+
) {
158+
return;
159+
}
160+
152161
const sourceParentInserted = this._isInInsertedElement( operation.sourcePosition.parent );
153162
const targetParentInserted = this._isInInsertedElement( operation.targetPosition.parent );
154163

tests/model/differ.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,35 @@ describe( 'Differ', () => {
629629
] );
630630
} );
631631
} );
632+
633+
// https://github.com/ckeditor/ckeditor5-engine/issues/1664
634+
it( 'move to the same position #1', () => {
635+
const position = new Position( root, [ 0 ] );
636+
637+
model.change( () => {
638+
move( position, 1, position );
639+
640+
expectChanges( [] );
641+
} );
642+
} );
643+
644+
// https://github.com/ckeditor/ckeditor5-engine/issues/1664
645+
it( 'move to the same position #2', () => {
646+
const sourcePosition = new Position( root, [ 0 ] );
647+
const targetPosition = new Position( root, [ 2 ] );
648+
649+
// Add two more elements to the root, now there are 4 paragraphs.
650+
root._appendChild( [
651+
new Element( 'paragraph' ),
652+
new Element( 'paragraph' )
653+
] );
654+
655+
model.change( () => {
656+
move( sourcePosition, 2, targetPosition );
657+
658+
expectChanges( [] );
659+
} );
660+
} );
632661
} );
633662

634663
describe( 'rename', () => {

0 commit comments

Comments
 (0)