Przeglądaj źródła

Rename StylesMap.insertProperty() to set().

Maciej Gołaszewski 6 lat temu
rodzic
commit
5c4e33c057

+ 2 - 2
packages/ckeditor5-engine/src/view/element.js

@@ -546,7 +546,7 @@ export default class Element extends Node {
 		// Classes and styles are cloned separately - this solution is faster than adding them back to attributes and
 		// parse once again in constructor.
 		cloned._classes = new Set( this._classes );
-		cloned._styles.insertProperty( this._styles.getNormalized() );
+		cloned._styles.set( this._styles.getNormalized() );
 
 		// Clone custom properties.
 		cloned._customProperties = new Map( this._customProperties );
@@ -741,7 +741,7 @@ export default class Element extends Node {
 	_setStyle( property, value ) {
 		this._fireChange( 'attributes', this );
 
-		this._styles.insertProperty( property, value );
+		this._styles.set( property, value );
 	}
 
 	/**

+ 5 - 5
packages/ckeditor5-engine/src/view/stylesmap.js

@@ -124,12 +124,12 @@ export default class StylesMap {
 	 *
 	 * Can insert one by one
 	 *
-	 *		styles.insertProperty( 'color', 'blue' );
-	 *		styles.insertProperty( 'margin-right', '1em' );
+	 *		styles.set( 'color', 'blue' );
+	 *		styles.set( 'margin-right', '1em' );
 	 *
 	 * or many styles at once:
 	 *
-	 *		styles.insertProperty( {
+	 *		styles.set( {
 	 *			color: 'blue',
 	 *			'margin-right': '1em'
 	 *		} );
@@ -140,10 +140,10 @@ export default class StylesMap {
 	 * @param {String|Object} value
 	 * @returns {Boolean}
 	 */
-	insertProperty( nameOrObject, value ) {
+	set( nameOrObject, value ) {
 		if ( isObject( nameOrObject ) ) {
 			for ( const key of Object.keys( nameOrObject ) ) {
-				this.insertProperty( key, nameOrObject[ key ] );
+				this.set( key, nameOrObject[ key ] );
 			}
 		} else {
 			this._styleProcessor.toNormalizedForm( nameOrObject, value, this._styles );

+ 3 - 3
packages/ckeditor5-engine/tests/view/styles/borderstyles.js

@@ -74,7 +74,7 @@ describe( 'Border styles normalization', () => {
 	} );
 
 	it( 'should output only defined inline styles', () => {
-		styles.insertProperty( 'border-color', { top: 'blue' } );
+		styles.set( 'border-color', { top: 'blue' } );
 
 		expect( styles.getNormalized( 'border' ) ).to.deep.equal( {
 			color: { top: 'blue' }
@@ -133,8 +133,8 @@ describe( 'Border styles normalization', () => {
 
 	it( 'should merge rules on insert other shorthand', () => {
 		styles.setTo( 'border:1px solid blue;' );
-		styles.insertProperty( 'border-left', '#665511 dashed 2.7em' );
-		styles.insertProperty( 'border-top', '7px dotted #ccc' );
+		styles.set( 'border-left', '#665511 dashed 2.7em' );
+		styles.set( 'border-top', '7px dotted #ccc' );
 
 		expect( styles.getInlineStyle() ).to.equal(
 			'border-bottom:1px solid blue;' +

+ 6 - 6
packages/ckeditor5-engine/tests/view/stylesmap.js

@@ -172,30 +172,30 @@ describe( 'StylesMap', () => {
 		} );
 	} );
 
-	describe( 'insertProperty()', () => {
+	describe( 'set()', () => {
 		it( 'should insert new property (empty styles)', () => {
-			stylesMap.insertProperty( 'color', 'blue' );
+			stylesMap.set( 'color', 'blue' );
 
 			expect( stylesMap.getInlineProperty( 'color' ) ).to.equal( 'blue' );
 		} );
 
 		it( 'should insert new property (other properties are set)', () => {
 			stylesMap.setTo( 'margin: 1px;' );
-			stylesMap.insertProperty( 'color', 'blue' );
+			stylesMap.set( 'color', 'blue' );
 
 			expect( stylesMap.getInlineProperty( 'color' ) ).to.equal( 'blue' );
 		} );
 
 		it( 'should overwrite property', () => {
 			stylesMap.setTo( 'color: red;' );
-			stylesMap.insertProperty( 'color', 'blue' );
+			stylesMap.set( 'color', 'blue' );
 
 			expect( stylesMap.getInlineProperty( 'color' ) ).to.equal( 'blue' );
 		} );
 
 		it( 'should set multiple styles by providing an object', () => {
 			stylesMap.setTo( 'color: red;' );
-			stylesMap.insertProperty( { color: 'blue', foo: '1px' } );
+			stylesMap.set( { color: 'blue', foo: '1px' } );
 
 			expect( stylesMap.getInlineProperty( 'color' ) ).to.equal( 'blue' );
 			expect( stylesMap.getInlineProperty( 'foo-top' ) ).to.equal( '1px' );
@@ -203,7 +203,7 @@ describe( 'StylesMap', () => {
 
 		it( 'should set object property', () => {
 			stylesMap.setTo( 'foo:1px;' );
-			stylesMap.insertProperty( 'foo', { right: '2px' } );
+			stylesMap.set( 'foo', { right: '2px' } );
 
 			expect( stylesMap.getInlineProperty( 'foo-left' ) ).to.equal( '1px' );
 			expect( stylesMap.getInlineProperty( 'foo-right' ) ).to.equal( '2px' );