This repository was archived by the owner on Jun 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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> 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' , ( ) => {
You can’t perform that action at this time.
0 commit comments