Selaa lähdekoodia

Fixed: In AttributeOperation, 0 as attribute value was treated as no value and caused removing attribute.

Szymon Cofalik 9 vuotta sitten
vanhempi
sitoutus
2b4c0cb54d

+ 2 - 2
packages/ckeditor5-engine/src/model/delta/attributedelta.js

@@ -163,7 +163,7 @@ function changeItem( batch, doc, key, value, item ) {
 				range = new Range( Position.createBefore( item ), Position.createAfter( item ) );
 			}
 
-			operation = new AttributeOperation( range, key, previousValue || null, value || null, doc.version );
+			operation = new AttributeOperation( range, key, previousValue, value, doc.version );
 		}
 
 		delta.addOperation( operation );
@@ -214,7 +214,7 @@ function changeRange( batch, doc, attributeKey, attributeValue, range ) {
 
 	function addOperation() {
 		let range = new Range( lastSplitPosition, position );
-		const operation = new AttributeOperation( range, attributeKey, attributeValueBefore || null, attributeValue || null, doc.version );
+		const operation = new AttributeOperation( range, attributeKey, attributeValueBefore, attributeValue, doc.version );
 
 		delta.addOperation( operation );
 		doc.applyOperation( operation );

+ 2 - 2
packages/ckeditor5-engine/src/model/operation/attributeoperation.js

@@ -60,7 +60,7 @@ export default class AttributeOperation extends Operation {
 		 * @readonly
 		 * @member {*} engine.model.operation.AttributeOperation#oldValue
 		 */
-		this.oldValue = oldValue;
+		this.oldValue = oldValue === undefined ? null : oldValue;
 
 		/**
 		 * New value of the attribute with given key or `null`, if operation should remove attribute.
@@ -68,7 +68,7 @@ export default class AttributeOperation extends Operation {
 		 * @readonly
 		 * @member {*} engine.model.operation.AttributeOperation#newValue
 		 */
-		this.newValue = newValue;
+		this.newValue = newValue === undefined ? null : newValue;
 	}
 
 	/**

+ 2 - 2
packages/ckeditor5-engine/tests/model/operation/attributeoperation.js

@@ -41,7 +41,7 @@ describe( 'AttributeOperation', () => {
 				new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
 				'key',
 				'oldValue',
-				null,
+				undefined, // `undefined` should also be accepted as a value, it is same as `null`.
 				doc.version
 			);
 
@@ -68,7 +68,7 @@ describe( 'AttributeOperation', () => {
 			new AttributeOperation(
 				new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
 				'isNew',
-				null,
+				undefined, // `undefined` should also be accepted as a value, it is same as `null`.
 				true,
 				doc.version
 			)