Переглянути джерело

Add support for padding shorthand.

Maciej Gołaszewski 6 роки тому
батько
коміт
84c9d237f8

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

@@ -179,8 +179,8 @@ function parseRule( key, value, styleObject ) {
 			bottom: { width: bottom },
 			left: { width: left }
 		} );
-	} else if ( key === 'margin' ) {
-		addStyle( styleObject, 'margin', getTopRightBottomLeftValues( value ) );
+	} else if ( key === 'margin' || key === 'padding' ) {
+		addStyle( styleObject, key, getTopRightBottomLeftValues( value ) );
 	} else {
 		addStyle( styleObject, key, value );
 	}

+ 46 - 0
packages/ckeditor5-engine/tests/view/styles.js

@@ -284,6 +284,52 @@ describe( 'Styles', () => {
 			} );
 		} );
 
+		describe( 'padding', () => {
+			it( 'should set all paddings (1 value defined)', () => {
+				styleProxy.setStyle( 'padding:1px;' );
+
+				expect( styleProxy.getModel( 'padding' ) ).to.deep.equal( {
+					top: '1px',
+					right: '1px',
+					bottom: '1px',
+					left: '1px'
+				} );
+			} );
+
+			it( 'should set all paddings (2 values defined)', () => {
+				styleProxy.setStyle( 'padding:1px .34cm;' );
+
+				expect( styleProxy.getModel( 'padding' ) ).to.deep.equal( {
+					top: '1px',
+					right: '.34cm',
+					bottom: '1px',
+					left: '.34cm'
+				} );
+			} );
+
+			it( 'should set all paddings (3 values defined)', () => {
+				styleProxy.setStyle( 'padding:1px .34cm 90.1rem;' );
+
+				expect( styleProxy.getModel( 'padding' ) ).to.deep.equal( {
+					top: '1px',
+					right: '.34cm',
+					bottom: '90.1rem',
+					left: '.34cm'
+				} );
+			} );
+
+			it( 'should set all paddings (4 values defined)', () => {
+				styleProxy.setStyle( 'padding:1px .34cm 90.1rem thick;' );
+
+				expect( styleProxy.getModel( 'padding' ) ).to.deep.equal( {
+					top: '1px',
+					right: '.34cm',
+					bottom: '90.1rem',
+					left: 'thick'
+				} );
+			} );
+		} );
+
 		describe( 'unknown rules', () => {
 			it( 'should left rules untouched', () => {
 				styleProxy.setStyle( 'foo-bar:baz 1px abc;baz: 2px 3em;' );