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

Commit 3a348fd

Browse files
author
Piotr Jasiun
authored
Merge pull request #1393 from ckeditor/t/1392
Fix: `model.Differ` should not throw when multiple, intersecting remove changes were buffered. Closes #1392.
2 parents bfadb47 + 9c8a0c9 commit 3a348fd

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/model/differ.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,11 @@ export default class Differ {
645645
}
646646

647647
if ( old.type == 'remove' ) {
648-
if ( inc.offset + inc.howMany <= old.offset ) {
648+
if ( incEnd <= old.offset ) {
649649
old.offset -= inc.howMany;
650650
} else if ( inc.offset < old.offset ) {
651-
old.offset = inc.offset;
652-
old.howMany += inc.nodesToHandle;
653-
654-
inc.nodesToHandle = 0;
651+
inc.nodesToHandle += old.howMany;
652+
old.howMany = 0;
655653
}
656654
}
657655

tests/model/differ.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,23 @@ describe( 'Differ', () => {
13211321
] );
13221322
} );
13231323
} );
1324+
1325+
// #1392.
1326+
it( 'remove is correctly transformed by multiple affecting changes', () => {
1327+
root._appendChildren( new Element( 'paragraph', null, new Text( 'xyz' ) ) );
1328+
1329+
model.change( () => {
1330+
rename( root.getChild( 1 ), 'heading' );
1331+
rename( root.getChild( 2 ), 'heading' );
1332+
remove( Position.createAt( root, 0 ), 3 );
1333+
1334+
expectChanges( [
1335+
{ type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 0 ] ) },
1336+
{ type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 0 ] ) },
1337+
{ type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 0 ] ) }
1338+
] );
1339+
} );
1340+
} );
13241341
} );
13251342

13261343
describe( 'getChanges()', () => {

0 commit comments

Comments
 (0)