8
0
Просмотр исходного кода

Handle attribute change on refreshed node.

Maciej Gołaszewski 5 лет назад
Родитель
Сommit
9fa12db14a

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

@@ -171,7 +171,7 @@ export default class Differ {
 		//
 		switch ( operation.type ) {
 			case 'insert': {
-				if ( this._isInInsertedElement( operation.position.parent ) ) {
+				if ( this._isInInsertedElement( operation.position.parent ) || this._isInRefreshedElement( operation.position.parent ) ) {
 					return;
 				}
 
@@ -183,7 +183,8 @@ export default class Differ {
 			case 'removeAttribute':
 			case 'changeAttribute': {
 				for ( const item of operation.range.getItems( { shallow: true } ) ) {
-					if ( this._isInInsertedElement( item.parent ) ) {
+					// Attribute change on refreshed element is ignored
+					if ( this._isInInsertedElement( item.parent ) || this._isInRefreshedElement( item ) ) {
 						continue;
 					}
 

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

@@ -1835,6 +1835,32 @@ describe( 'Differ', () => {
 				], true );
 			} );
 		} );
+
+		it( 'an element with child added', () => {
+			const complex = root.getChild( 2 );
+
+			model.change( () => {
+				differ._pocRefreshItem( complex );
+				insert( new Element( 'slot' ), model.createPositionAt( complex, 2 ) );
+
+				expectChanges( [
+					{ type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
+				], true );
+			} );
+		} );
+
+		it( 'an element with attribute set', () => {
+			const complex = root.getChild( 2 );
+
+			model.change( () => {
+				differ._pocRefreshItem( complex );
+				attribute( model.createRangeOn( complex ), 'foo', undefined, true );
+
+				expectChanges( [
+					{ type: 'refresh', name: 'complex', length: 1, position: model.createPositionBefore( complex ) }
+				], true );
+			} );
+		} );
 	} );
 
 	describe( 'refreshItem()', () => {