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

Commit 7175b6c

Browse files
author
Piotr Jasiun
authored
Merge pull request #182 from ckeditor/t/181
Fix: Mutation handling crashed in particular scenarios (when the old text was the same as the new text). Closes #181.
2 parents d3331ac + 15f8116 commit 7175b6c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/utils/injecttypingmutationshandling.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ class MutationHandler {
200200
// To have correct `diffResult`, we also compare view node text data with   replaced by space.
201201
const oldText = mutation.oldText.replace( /\u00A0/g, ' ' );
202202

203+
// Do nothing if mutations created same text.
204+
if ( oldText === newText ) {
205+
return;
206+
}
207+
203208
const diffResult = diff( oldText, newText );
204209

205210
const { firstChangeAt, insertions, deletions } = calculateChanges( diffResult );

tests/input.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,32 @@ describe( 'Input feature', () => {
647647

648648
expect( getViewData( view ) ).to.equal( '<p>foo<placeholder></placeholder>bar<placeholder></placeholder>baz!{}</p>' );
649649
} );
650+
651+
// https://github.com/ckeditor/ckeditor5-typing/issues/181
652+
it( 'should not crash if the mutation old text is same as new text', () => {
653+
// It shouldn't matter what data is here, I am putting it like it is in the test scenario, but it is really about
654+
// what mutations are generated.
655+
editor.setData( '<p>Foo<strong> </strong>&nbsp;Bar</p>' );
656+
657+
const p = viewRoot.getChild( 0 );
658+
659+
viewDocument.fire( 'mutations', [
660+
{
661+
type: 'text',
662+
oldText: ' ',
663+
newText: ' ',
664+
node: p.getChild( 1 )
665+
},
666+
{
667+
type: 'text',
668+
oldText: 'Foo',
669+
newText: 'Foox',
670+
node: p.getChild( 0 )
671+
}
672+
] );
673+
674+
expect( getViewData( view ) ).to.equal( '<p>Foox{}<strong> </strong> Bar</p>' );
675+
} );
650676
} );
651677

652678
describe( 'keystroke handling', () => {

0 commit comments

Comments
 (0)