@@ -41,7 +41,7 @@ describe( 'Input feature', () => {
4141
4242 return VirtualTestEditor
4343 . create ( {
44- plugins : [ Input , Paragraph ]
44+ plugins : [ Input , Paragraph , Bold ]
4545 } )
4646 . then ( newEditor => {
4747 // Mock image feature.
@@ -126,6 +126,50 @@ describe( 'Input feature', () => {
126126 expect ( getViewData ( view ) ) . to . equal ( '<p>x{}</p>' ) ;
127127 } ) ;
128128
129+ it ( 'should handle multiple text mutations' , ( ) => {
130+ editor . setData ( '<p>foo<strong>bar</strong></p>' ) ;
131+
132+ view . fire ( 'mutations' , [
133+ {
134+ type : 'text' ,
135+ oldText : 'foo' ,
136+ newText : 'foob' ,
137+ node : viewRoot . getChild ( 0 ) . getChild ( 0 )
138+ } ,
139+ {
140+ type : 'text' ,
141+ oldText : 'bar' ,
142+ newText : 'ar' ,
143+ node : viewRoot . getChild ( 0 ) . getChild ( 1 ) . getChild ( 0 )
144+ }
145+ ] ) ;
146+
147+ expect ( getModelData ( model ) ) . to . equal ( '<paragraph>foob[]<$text bold="true">ar</$text></paragraph>' ) ;
148+ expect ( getViewData ( view ) ) . to . equal ( '<p>foob{}<strong>ar</strong></p>' ) ;
149+ } ) ;
150+
151+ it ( 'should handle multiple text node insertion' , ( ) => {
152+ editor . setData ( '<p></p><p></p>' ) ;
153+
154+ view . fire ( 'mutations' , [
155+ {
156+ type : 'children' ,
157+ oldChildren : [ ] ,
158+ newChildren : [ new ViewText ( 'x' ) ] ,
159+ node : viewRoot . getChild ( 0 )
160+ } ,
161+ {
162+ type : 'children' ,
163+ oldChildren : [ ] ,
164+ newChildren : [ new ViewText ( 'y' ) ] ,
165+ node : viewRoot . getChild ( 1 )
166+ }
167+ ] ) ;
168+
169+ expect ( getModelData ( model ) ) . to . equal ( '<paragraph>x</paragraph><paragraph>y[]</paragraph>' ) ;
170+ expect ( getViewData ( view ) ) . to . equal ( '<p>x</p><p>y{}</p>' ) ;
171+ } ) ;
172+
129173 it ( 'should do nothing when two nodes were inserted' , ( ) => {
130174 editor . setData ( '<p></p>' ) ;
131175
@@ -947,6 +991,36 @@ describe( 'Input feature', () => {
947991 expect ( getModelData ( model ) ) . to . equal ( '<paragraph><$text bold="true">[]textx</$text></paragraph>' ) ;
948992 expect ( getViewData ( view ) ) . to . equal ( '<p><strong>{}textx</strong></p>' ) ;
949993 } ) ;
994+
995+ // #117.
996+ it ( 'should handle mixed mutations' , ( ) => {
997+ setModelData ( model , '<paragraph><$text bold="true">Foo bar aple</$text></paragraph>' ) ;
998+
999+ const paragraph = viewRoot . getChild ( 0 ) ;
1000+ const strong = paragraph . getChild ( 0 ) ;
1001+ const viewSelection = new ViewSelection ( ) ;
1002+ viewSelection . setCollapsedAt ( paragraph , 0 ) ;
1003+
1004+ // Simulate mutations and DOM change.
1005+ domRoot . childNodes [ 0 ] . innerHTML = '<strong>Foo bar </strong><b>apple</b>' ;
1006+ view . fire ( 'mutations' , [
1007+ {
1008+ type : 'text' ,
1009+ oldText : 'Foo bar aple' ,
1010+ newText : 'Foo bar ' ,
1011+ node : viewRoot . getChild ( 0 ) . getChild ( 0 )
1012+ } ,
1013+ {
1014+ type : 'children' ,
1015+ oldChildren : [ strong ] ,
1016+ newChildren : [ strong , new ViewElement ( 'b' , null , new ViewText ( 'apple' ) ) ] ,
1017+ node : paragraph
1018+ }
1019+ ] , viewSelection ) ;
1020+
1021+ expect ( getModelData ( model ) ) . to . equal ( '<paragraph><$text bold="true">[]Foo bar apple</$text></paragraph>' ) ;
1022+ expect ( getViewData ( view ) ) . to . equal ( '<p><strong>{}Foo bar apple</strong></p>' ) ;
1023+ } ) ;
9501024 } ) ;
9511025} ) ;
9521026
0 commit comments