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

Commit

Permalink
Merge pull request #1393 from ckeditor/t/1392
Browse files Browse the repository at this point in the history
Fix: `model.Differ` should not throw when multiple, intersecting remove changes were buffered. Closes #1392.
  • Loading branch information
Piotr Jasiun committed Apr 4, 2018
2 parents bfadb47 + 9c8a0c9 commit 3a348fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/model/differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/model/differ.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 3a348fd

Please sign in to comment.