Przeglądaj źródła

Add support for border-style shorthand.

Maciej Gołaszewski 6 lat temu
rodzic
commit
d9b8ffc84b

+ 9 - 0
packages/ckeditor5-engine/src/view/styles.js

@@ -161,6 +161,15 @@ function parseRule( key, value, styleObject ) {
 			bottom: { color: bottom },
 			left: { color: left }
 		} );
+	} else if ( key === 'border-style' ) {
+		const { top, bottom, right, left } = getTopRightBottomLeftValues( value );
+
+		addStyle( styleObject, 'border', {
+			top: { style: top },
+			right: { style: right },
+			bottom: { style: bottom },
+			left: { style: left }
+		} );
 	} else {
 		addStyle( styleObject, key, value );
 	}

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

@@ -165,6 +165,52 @@ describe( 'Styles', () => {
 					} );
 				} );
 			} );
+
+			describe( 'border-style', () => {
+				it( 'should set all border styles (1 value defined)', () => {
+					styleProxy.setStyle( 'border-style:solid;' );
+
+					expect( styleProxy.getModel( 'border' ) ).to.deep.equal( {
+						top: { style: 'solid' },
+						left: { style: 'solid' },
+						bottom: { style: 'solid' },
+						right: { style: 'solid' }
+					} );
+				} );
+
+				it( 'should set all border styles (2 values defined)', () => {
+					styleProxy.setStyle( 'border-style:solid dotted;' );
+
+					expect( styleProxy.getModel( 'border' ) ).to.deep.equal( {
+						top: { style: 'solid' },
+						right: { style: 'dotted' },
+						bottom: { style: 'solid' },
+						left: { style: 'dotted' }
+					} );
+				} );
+
+				it( 'should set all border styles (3 values defined)', () => {
+					styleProxy.setStyle( 'border-style:solid dotted dashed;' );
+
+					expect( styleProxy.getModel( 'border' ) ).to.deep.equal( {
+						top: { style: 'solid' },
+						right: { style: 'dotted' },
+						bottom: { style: 'dashed' },
+						left: { style: 'dotted' }
+					} );
+				} );
+
+				it( 'should set all border styles (4 values defined)', () => {
+					styleProxy.setStyle( 'border-style:solid dotted dashed ridge;' );
+
+					expect( styleProxy.getModel( 'border' ) ).to.deep.equal( {
+						top: { style: 'solid' },
+						right: { style: 'dotted' },
+						bottom: { style: 'dashed' },
+						left: { style: 'ridge' }
+					} );
+				} );
+			} );
 		} );
 
 		describe( 'unknown rules', () => {