@@ -641,6 +641,18 @@ describe( 'Differ', () => {
641641 ] ) ;
642642 } ) ;
643643 } ) ;
644+
645+ it ( 'inside a new element' , ( ) => {
646+ // Since the rename is inside a new element, it should not be listed on changes list.
647+ model . change ( ( ) => {
648+ insert ( new Element ( 'blockQuote' , null , new Element ( 'paragraph' ) ) , new Position ( root , [ 2 ] ) ) ;
649+ rename ( root . getChild ( 2 ) . getChild ( 0 ) , 'listItem' ) ;
650+
651+ expectChanges ( [
652+ { type : 'insert' , name : 'blockQuote' , length : 1 , position : new Position ( root , [ 2 ] ) }
653+ ] ) ;
654+ } ) ;
655+ } ) ;
644656 } ) ;
645657
646658 describe ( 'attribute' , ( ) => {
@@ -1230,7 +1242,10 @@ describe( 'Differ', () => {
12301242 } ) ;
12311243 } ) ;
12321244
1233- it ( 'proper filtering of changes in inserted elements' , ( ) => {
1245+ // In this scenario we create a new element, then remove something from before it to mess up with offsets,
1246+ // finally we insert some content into a new element. Since we are inserting into a new element, the
1247+ // inserted children should not be shown on changes list.
1248+ it ( 'proper filtering of changes in inserted elements #1' , ( ) => {
12341249 root . removeChildren ( 0 , root . childCount ) ;
12351250 root . appendChildren ( new Element ( 'image' ) ) ;
12361251
@@ -1250,6 +1265,26 @@ describe( 'Differ', () => {
12501265 ] ) ;
12511266 } ) ;
12521267 } ) ;
1268+
1269+ // In this scenario we create a new element, then move another element that was before the new element into
1270+ // the new element. This way we mess up with offsets and insert content into a new element in one operation.
1271+ // Since we are inserting into a new element, the insertion of moved element should not be shown on changes list.
1272+ it ( 'proper filtering of changes in inserted elements #2' , ( ) => {
1273+ root . removeChildren ( 0 , root . childCount ) ;
1274+ root . appendChildren ( new Element ( 'image' ) ) ;
1275+
1276+ model . change ( ( ) => {
1277+ // Insert `div` after `image`.
1278+ insert ( new Element ( 'div' ) , new Position ( root , [ 1 ] ) ) ;
1279+ // Move `image` to the new `div`.
1280+ move ( new Position ( root , [ 0 ] ) , 1 , new Position ( root , [ 1 , 0 ] ) ) ;
1281+
1282+ expectChanges ( [
1283+ { type : 'remove' , name : 'image' , length : 1 , position : new Position ( root , [ 0 ] ) } ,
1284+ { type : 'insert' , name : 'div' , length : 1 , position : new Position ( root , [ 0 ] ) }
1285+ ] ) ;
1286+ } ) ;
1287+ } ) ;
12531288 } ) ;
12541289
12551290 describe ( 'getChanges()' , ( ) => {
@@ -1410,6 +1445,8 @@ describe( 'Differ', () => {
14101445 function expectChanges ( expected , includeChangesInGraveyard = false ) {
14111446 const changes = differ . getChanges ( { includeChangesInGraveyard } ) ;
14121447
1448+ expect ( changes . length ) . to . equal ( expected . length ) ;
1449+
14131450 for ( let i = 0 ; i < expected . length ; i ++ ) {
14141451 for ( const key in expected [ i ] ) {
14151452 if ( expected [ i ] . hasOwnProperty ( key ) ) {
0 commit comments