소스 검색

Font-family dropdown will try to match the current value with items in dropdown.

Kamil Piechaczek 5 년 전
부모
커밋
dd1574873a
2개의 변경된 파일48개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      packages/ckeditor5-font/src/fontfamily/fontfamilyui.js
  2. 36 0
      packages/ckeditor5-font/tests/fontfamily/fontfamilyui.js

+ 12 - 1
packages/ckeditor5-font/src/fontfamily/fontfamilyui.js

@@ -109,7 +109,18 @@ function _prepareListOptions( options, command ) {
 			} )
 			} )
 		};
 		};
 
 
-		def.model.bind( 'isOn' ).to( command, 'value', value => value === option.model );
+		def.model.bind( 'isOn' ).to( command, 'value', value => {
+			// "Default" or check in strict font-family converters mode.
+			if ( value === option.model ) {
+				return true;
+			}
+
+			if ( !value || !option.model ) {
+				return false;
+			}
+
+			return value.split( ',' )[ 0 ].replace( /'/g, '' ).toLowerCase() === option.model.toLowerCase();
+		} );
 
 
 		// Try to set a dropdown list item style.
 		// Try to set a dropdown list item style.
 		if ( option.view && option.view.styles ) {
 		if ( option.view && option.view.styles ) {

+ 36 - 0
packages/ckeditor5-font/tests/fontfamily/fontfamilyui.js

@@ -104,6 +104,42 @@ describe( 'FontFamilyUI', () => {
 				.to.deep.equal( [ false, true, false, false, false, false, false, false, false ] );
 				.to.deep.equal( [ false, true, false, false, false, false, false, false, false ] );
 		} );
 		} );
 
 
+		it( 'should activate current option in dropdown for full font family definitions', () => {
+			const element = document.createElement( 'div' );
+			document.body.appendChild( element );
+
+			return ClassicTestEditor
+				.create( element, {
+					plugins: [ FontFamilyEditing, FontFamilyUI ],
+					fontSize: {
+						disableValueMatching: true
+					}
+				} )
+				.then( editor => {
+					const command = editor.commands.get( 'fontFamily' );
+					const dropdown = editor.ui.componentFactory.create( 'fontFamily' );
+
+					const listView = dropdown.listView;
+
+					command.value = undefined;
+
+					// The first item is 'default' font family.
+					expect( listView.items.map( item => item.children.first.isOn ) )
+						.to.deep.equal( [ true, false, false, false, false, false, false, false, false ] );
+
+					command.value = '\'Courier New\', Courier, monospace';
+
+					// The third item is 'Courier New' font family.
+					expect( listView.items.map( item => item.children.first.isOn ) )
+						.to.deep.equal( [ false, false, true, false, false, false, false, false, false ] );
+
+					return editor.destroy();
+				} )
+				.then( () => {
+					element.remove();
+				} );
+		} );
+
 		describe( 'model to command binding', () => {
 		describe( 'model to command binding', () => {
 			it( 'isEnabled', () => {
 			it( 'isEnabled', () => {
 				command.isEnabled = false;
 				command.isEnabled = false;