|
|
@@ -1789,11 +1789,11 @@ describe( 'Differ', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'reInsertItem()', () => {
|
|
|
+ describe( 'refreshItem()', () => {
|
|
|
it( 'should mark given element to be removed and added again', () => {
|
|
|
const p = root.getChild( 0 );
|
|
|
|
|
|
- differ.reInsertItem( p );
|
|
|
+ differ.refreshItem( p );
|
|
|
|
|
|
expectChanges( [
|
|
|
{ type: 'remove', name: 'paragraph', length: 1, position: model.createPositionBefore( p ) },
|
|
|
@@ -1806,7 +1806,7 @@ describe( 'Differ', () => {
|
|
|
const range = model.createRangeIn( p );
|
|
|
const textProxy = [ ...range.getItems() ][ 0 ];
|
|
|
|
|
|
- differ.reInsertItem( textProxy );
|
|
|
+ differ.refreshItem( textProxy );
|
|
|
|
|
|
expectChanges( [
|
|
|
{ type: 'remove', name: '$text', length: 3, position: model.createPositionAt( p, 0 ) },
|
|
|
@@ -1814,327 +1814,6 @@ describe( 'Differ', () => {
|
|
|
], true );
|
|
|
} );
|
|
|
|
|
|
- it( 'inside a new element', () => {
|
|
|
- // Since the refreshed element is inside a new element, it should not be listed on changes list.
|
|
|
- model.change( () => {
|
|
|
- insert( new Element( 'blockQuote', null, new Element( 'paragraph' ) ), new Position( root, [ 2 ] ) );
|
|
|
-
|
|
|
- differ.reInsertItem( root.getChild( 2 ).getChild( 0 ) );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'insert', name: 'blockQuote', length: 1, position: new Position( root, [ 2 ] ) }
|
|
|
- ] );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'markers refreshing', () => {
|
|
|
- model.change( () => {
|
|
|
- // Refreshed element contains marker.
|
|
|
- model.markers._set( 'markerA', new Range( new Position( root, [ 1, 1 ] ), new Position( root, [ 1, 2 ] ) ) );
|
|
|
-
|
|
|
- // Marker contains refreshed element.
|
|
|
- model.markers._set( 'markerB', new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ) );
|
|
|
-
|
|
|
- // Intersecting.
|
|
|
- model.markers._set( 'markerC', new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 2 ] ) ) );
|
|
|
-
|
|
|
- // Not intersecting.
|
|
|
- model.markers._set( 'markerD', new Range( new Position( root, [ 0, 0 ] ), new Position( root, [ 1 ] ) ) );
|
|
|
- } );
|
|
|
-
|
|
|
- const markersToRefresh = [ 'markerA', 'markerB', 'markerC' ];
|
|
|
-
|
|
|
- differ.reInsertItem( root.getChild( 1 ) );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) },
|
|
|
- { type: 'insert', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) }
|
|
|
- ] );
|
|
|
-
|
|
|
- const markersToRemove = differ.getMarkersToRemove().map( entry => entry.name );
|
|
|
- const markersToAdd = differ.getMarkersToAdd().map( entry => entry.name );
|
|
|
-
|
|
|
- expect( markersToRefresh ).to.deep.equal( markersToRemove );
|
|
|
- expect( markersToRefresh ).to.deep.equal( markersToAdd );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- describe( 'refreshItem()', () => {
|
|
|
- beforeEach( () => {
|
|
|
- root._appendChild( [
|
|
|
- new Element( 'complex', null, [
|
|
|
- new Element( 'slot', null, [
|
|
|
- new Element( 'paragraph', null, new Text( '1' ) )
|
|
|
- ] ),
|
|
|
- new Element( 'slot', null, [
|
|
|
- new Element( 'paragraph', null, new Text( '2' ) )
|
|
|
- ] )
|
|
|
- ] )
|
|
|
- ] );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element (block)', () => {
|
|
|
- const p = root.getChild( 0 );
|
|
|
-
|
|
|
- differ.refreshItem( p );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'paragraph', length: 1, position: model.createPositionBefore( p ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'an element refreshed multiple times', () => {
|
|
|
- const p = root.getChild( 0 );
|
|
|
-
|
|
|
- differ.refreshItem( p );
|
|
|
- differ.refreshItem( p );
|
|
|
- differ.refreshItem( p );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'paragraph', length: 1, position: model.createPositionBefore( p ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element (complex)', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- differ.refreshItem( complex );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a multiple elements refreshed', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- differ.refreshItem( complex.getChild( 0 ) );
|
|
|
- differ.refreshItem( complex.getChild( 1 ) );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'slot', length: 1, position: model.createPositionAt( complex, 0 ) },
|
|
|
- { type: 'refresh', name: 'slot', length: 1, position: model.createPositionAt( complex, 1 ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element with a child removed (refresh + remove)', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- differ.refreshItem( complex );
|
|
|
- remove( model.createPositionAt( complex, 1 ), 1 );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element with a child removed (remove + refresh)', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- remove( model.createPositionAt( complex, 1 ), 1 );
|
|
|
- differ.refreshItem( complex );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) },
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAfter( complex.getChild( 0 ) ) }
|
|
|
- ], false );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element with a child added (refresh + insert)', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- differ.refreshItem( complex );
|
|
|
- insert( new Element( 'slot' ), model.createPositionAt( complex, 2 ) );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element with a child added (insert + refresh)', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- const slot = new Element( 'slot' );
|
|
|
- insert( slot, model.createPositionAt( complex, 2 ) );
|
|
|
- differ.refreshItem( complex );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionBefore( slot ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element with attribute set (refresh + attribute)', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- differ.refreshItem( complex );
|
|
|
- attribute( model.createRangeOn( complex ), 'foo', undefined, true );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'a refreshed element with attribute set (attribute + refresh)', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- attribute( model.createRangeOn( complex ), 'foo', undefined, true );
|
|
|
- differ.refreshItem( complex );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'an element added and refreshed', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- const slot = new Element( 'slot' );
|
|
|
- insert( slot, model.createPositionAt( complex, 2 ) );
|
|
|
- differ.refreshItem( slot );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionBefore( slot ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'multiple elements added and one of them refreshed (first)', () => {
|
|
|
- const complexSource = root.getChild( 2 );
|
|
|
- complexSource._appendChild( new Element( 'slot' ) );
|
|
|
- root._appendChild( [ new Element( 'complex' ) ] );
|
|
|
-
|
|
|
- const complexTarget = root.getChild( 3 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- move( model.createPositionAt( complexSource, 0 ), 3, model.createPositionAt( complexTarget, 0 ) );
|
|
|
- const slot = complexTarget.getChild( 0 );
|
|
|
- differ.refreshItem( slot );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 0 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 1 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 2 ) }
|
|
|
- ], false );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'multiple elements added and one of them refreshed (last)', () => {
|
|
|
- const complexSource = root.getChild( 2 );
|
|
|
- complexSource._appendChild( new Element( 'slot' ) );
|
|
|
- root._appendChild( [ new Element( 'complex' ) ] );
|
|
|
-
|
|
|
- const complexTarget = root.getChild( 3 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- move( model.createPositionAt( complexSource, 0 ), 3, model.createPositionAt( complexTarget, 0 ) );
|
|
|
- const slot = complexTarget.getChild( 2 );
|
|
|
- differ.refreshItem( slot );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 0 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 1 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 2 ) }
|
|
|
- ], false );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'multiple elements added and one of them refreshed (inner)', () => {
|
|
|
- const complexSource = root.getChild( 2 );
|
|
|
- complexSource._appendChild( new Element( 'slot' ) );
|
|
|
- root._appendChild( [ new Element( 'complex' ) ] );
|
|
|
-
|
|
|
- const complexTarget = root.getChild( 3 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- move( model.createPositionAt( complexSource, 0 ), 3, model.createPositionAt( complexTarget, 0 ) );
|
|
|
- const slot = complexTarget.getChild( 1 );
|
|
|
- differ.refreshItem( slot );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complexSource, 0 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 0 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 1 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complexTarget, 2 ) }
|
|
|
- ], false );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'an element added and other refreshed', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- const slot = new Element( 'slot' );
|
|
|
- insert( slot, model.createPositionAt( complex, 2 ) );
|
|
|
- differ.refreshItem( complex.getChild( 0 ) );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'slot', length: 1, position: model.createPositionAt( complex, 0 ) },
|
|
|
- { type: 'insert', name: 'slot', length: 1, position: model.createPositionAt( complex, 2 ) }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'an element added attribute and other refreshed', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- const attributeChild = complex.getChild( 1 );
|
|
|
- const refreshChild = complex.getChild( 0 );
|
|
|
- attribute( model.createRangeOn( attributeChild ), 'foo', undefined, true );
|
|
|
- differ.refreshItem( refreshChild );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'refresh', name: 'slot', length: 1, position: model.createPositionBefore( refreshChild ) },
|
|
|
- {
|
|
|
- type: 'attribute',
|
|
|
- range: model.createRange(
|
|
|
- model.createPositionBefore( attributeChild ),
|
|
|
- model.createPositionAt( attributeChild, 0 )
|
|
|
- ),
|
|
|
- attributeKey: 'foo',
|
|
|
- attributeOldValue: null,
|
|
|
- attributeNewValue: true
|
|
|
- }
|
|
|
- ], true );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'an element refreshed and removed', () => {
|
|
|
- const complex = root.getChild( 2 );
|
|
|
-
|
|
|
- model.change( () => {
|
|
|
- const slot = complex.getChild( 1 );
|
|
|
- remove( model.createPositionAt( complex, 1 ), 1 );
|
|
|
- differ.refreshItem( slot );
|
|
|
-
|
|
|
- expectChanges( [
|
|
|
- { type: 'remove', name: 'slot', length: 1, position: model.createPositionAt( complex, 1 ) }
|
|
|
- ] );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
it( 'inside a new element', () => {
|
|
|
// Since the refreshed element is inside a new element, it should not be listed on changes list.
|
|
|
model.change( () => {
|
|
|
@@ -2168,7 +1847,8 @@ describe( 'Differ', () => {
|
|
|
differ.refreshItem( root.getChild( 1 ) );
|
|
|
|
|
|
expectChanges( [
|
|
|
- { type: 'refresh', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) }
|
|
|
+ { type: 'remove', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) },
|
|
|
+ { type: 'insert', name: 'paragraph', length: 1, position: new Position( root, [ 1 ] ) }
|
|
|
] );
|
|
|
|
|
|
const markersToRemove = differ.getMarkersToRemove().map( entry => entry.name );
|