Selaa lähdekoodia

Added more methods for changing attributes to the Batch interface.

Oskar Wróbel 8 vuotta sitten
vanhempi
commit
26bbe5f4df
1 muutettua tiedostoa jossa 22 lisäystä ja 0 poistoa
  1. 22 0
      packages/ckeditor5-engine/src/model/batch.js

+ 22 - 0
packages/ckeditor5-engine/src/model/batch.js

@@ -223,6 +223,12 @@ export default class Batch {
 		return this;
 	}
 
+	setAttributes( itemOrRange, attributes ) {
+		for ( const attribute of Object.keys( attributes ) ) {
+			this.setAttribute( itemOrRange, attribute, attributes[ attribute ] );
+		}
+	}
+
 	/**
 	 * Removes an attribute with given key from a {@link module:engine/model/item~Item model item}
 	 * or from a {@link module:engine/model/range~Range range}.
@@ -243,6 +249,22 @@ export default class Batch {
 		return this;
 	}
 
+	clearAttributes( itemOrRange ) {
+		const removeAttributesFromItem = item => {
+			for ( const attribute of item.getAttributeKeys() ) {
+				this.removeAttribute( item, attribute );
+			}
+		};
+
+		if ( !( itemOrRange instanceof Range ) ) {
+			removeAttributesFromItem( itemOrRange );
+		} else {
+			for ( const item of itemOrRange.getItems() ) {
+				removeAttributesFromItem( item );
+			}
+		}
+	}
+
 	/**
 	 * Merges two siblings at the given position.
 	 *