Browse Source

Using writer to remove styles from view element.

Szymon Kupś 7 years ago
parent
commit
556356f072

+ 17 - 14
packages/ckeditor5-engine/src/view/element.js

@@ -487,20 +487,6 @@ export default class Element extends Node {
 	}
 
 	/**
-	 * Removes specified style.
-	 *
-	 *		element.removeStyle( 'color' );  // Removes 'color' style.
-	 *		element.removeStyle( 'color', 'border-top' ); // Removes both 'color' and 'border-top' styles.
-	 *
-	 * @param {...String} property
-	 * @fires module:engine/view/node~Node#change
-	 */
-	removeStyle( ...property ) {
-		this._fireChange( 'attributes', this );
-		property.forEach( name => this._styles.delete( name ) );
-	}
-
-	/**
 	 * Returns ancestor element that match specified pattern.
 	 * Provided patterns should be compatible with {@link module:engine/view/matcher~Matcher Matcher} as it is used internally.
 	 *
@@ -720,6 +706,23 @@ export default class Element extends Node {
 	}
 
 	/**
+	 * Removes specified style.
+	 *
+	 *		element._removeStyle( 'color' );  // Removes 'color' style.
+	 *		element._removeStyle( [ 'color', 'border-top' ] ); // Removes both 'color' and 'border-top' styles.
+	 *
+	 * @protected
+	 * @param {Array.<String>|String} property
+	 * @fires module:engine/view/node~Node#change
+	 */
+	_removeStyle( property ) {
+		this._fireChange( 'attributes', this );
+
+		property = Array.isArray( property ) ? property : [ property ];
+		property.forEach( name => this._styles.delete( name ) );
+	}
+
+	/**
 	 * Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
 	 *
 	 * @abstract

+ 5 - 1
packages/ckeditor5-engine/src/view/writer.js

@@ -202,6 +202,10 @@ export default class Writer {
 		element._setStyle( property, value );
 	}
 
+	removeStyle( property, element ) {
+		element._removeStyle( property );
+	}
+
 	/**
 	 * Breaks attribute nodes at provided position or at boundaries of provided range. It breaks attribute elements inside
 	 * up to a container element.
@@ -1120,7 +1124,7 @@ export default class Writer {
 		this.removeClass( Array.from( wrapper.getClassNames() ), toUnwrap );
 
 		// Remove all wrapper's styles from unwrapped element.
-		toUnwrap.removeStyle( ...wrapper.getStyleNames() );
+		this.removeStyle( Array.from( wrapper.getStyleNames() ), toUnwrap );
 
 		return true;
 	}

+ 4 - 4
packages/ckeditor5-engine/tests/view/element.js

@@ -833,10 +833,10 @@ describe( 'Element', () => {
 			} );
 		} );
 
-		describe( 'removeStyle', () => {
+		describe( '_removeStyle()', () => {
 			it( 'should remove style', () => {
 				el._setStyle( 'padding-top', '10px' );
-				el.removeStyle( 'padding-top' );
+				el._removeStyle( 'padding-top' );
 
 				expect( el.hasStyle( 'padding-top' ) ).to.be.false;
 			} );
@@ -848,7 +848,7 @@ describe( 'Element', () => {
 					done();
 				} );
 
-				el.removeStyle( 'color' );
+				el._removeStyle( 'color' );
 			} );
 
 			it( 'should remove multiple styles', () => {
@@ -857,7 +857,7 @@ describe( 'Element', () => {
 					'margin-top': '10px',
 					'color': 'red'
 				} );
-				el.removeStyle( 'padding-top', 'margin-top' );
+				el._removeStyle( [ 'padding-top', 'margin-top' ] );
 
 				expect( el.hasStyle( 'padding-top' ) ).to.be.false;
 				expect( el.hasStyle( 'margin-top' ) ).to.be.false;