Ver código fonte

Refresh change should be forfeit also when inside range insert (multiple nodes).

Maciej Gołaszewski 5 anos atrás
pai
commit
3e9c9ebb7b

+ 2 - 2
packages/ckeditor5-engine/src/model/differ.js

@@ -932,8 +932,8 @@ export default class Differ {
 
 			if ( inc.type === 'refresh' ) {
 				if ( old.type === 'insert' ) {
-					// Refreshing newly inserted element makes no sense and should not be processed.
-					if ( inc.offset === old.offset && inc.howMany === old.howMany ) {
+					if ( inc.offset >= old.offset && inc.offset < oldEnd ) {
+						// if ( inc.offset === old.offset && inc.howMany === old.howMany ) {
 						inc.nodesToHandle = 0;
 					}
 				}

+ 69 - 0
packages/ckeditor5-engine/tests/model/differ.js

@@ -1988,6 +1988,75 @@ describe( 'Differ', () => {
 			} );
 		} );
 
+		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 );