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

Fixed: `model.Differ` returned wrong values on `getChanges()` if an element had an attribute that didn't change.

Szymon Cofalik 8 лет назад
Родитель
Сommit
57a1a800e0

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

@@ -786,10 +786,10 @@ export default class Differ {
 					attributeNewValue: newValue,
 					changeCount: this._changeCount++
 				} );
-
-				// Prevent returning two diff items for the same change.
-				newAttributes.delete( key );
 			}
+
+			// Prevent returning two diff items for the same change.
+			newAttributes.delete( key );
 		}
 
 		// Look through new attributes that weren't handled above.

+ 7 - 2
packages/ckeditor5-engine/tests/model/differ.js

@@ -534,10 +534,15 @@ describe( 'Differ', () => {
 		} );
 
 		it( 'on an element - only one of many attributes changes', () => {
-			root.getChild( 0 ).setAttribute( 'otherAttr', true );
-
 			const range = Range.createFromParentsAndOffsets( root, 0, root.getChild( 0 ), 0 );
 
+			// Set an attribute on an element. It won't change afterwards.
+			attribute( range, 'otherAttr', null, true );
+
+			// "Flush" differ.
+			differ.getChanges();
+			differ.reset();
+
 			attribute( range, attributeKey, attributeOldValue, attributeNewValue );
 
 			expectChanges( [