浏览代码

Feature: Marked active heading in the dropdown list.

Aleksander Nowodzinski 8 年之前
父节点
当前提交
e115f6d548
共有 2 个文件被更改,包括 22 次插入4 次删除
  1. 9 4
      packages/ckeditor5-heading/src/heading.js
  2. 13 0
      packages/ckeditor5-heading/tests/heading.js

+ 9 - 4
packages/ckeditor5-heading/src/heading.js

@@ -41,14 +41,19 @@ export default class Heading extends Plugin {
 		let defaultOption;
 
 		for ( let option of options ) {
-			// Add the option to the collection.
-			dropdownItems.add( new Model( {
+			const command = editor.commands.get( option.modelElement );
+			const itemModel = new Model( {
 				commandName: option.modelElement,
 				label: option.title,
 				class: option.class
-			} ) );
+			} );
+
+			itemModel.bind( 'isActive' ).to( command, 'value' );
+
+			// Add the option to the collection.
+			dropdownItems.add( itemModel );
 
-			commands.push( editor.commands.get( option.modelElement ) );
+			commands.push( command );
 
 			if ( !defaultOption && option.modelElement == 'paragraph' ) {
 				defaultOption = option;

+ 13 - 0
packages/ckeditor5-heading/tests/heading.js

@@ -210,6 +210,19 @@ describe( 'Heading', () => {
 					'ck-heading_heading3'
 				] );
 			} );
+
+			it( 'reflects the #value of the commands', () => {
+				const listView = dropdown.listView;
+
+				editor.commands.get( 'heading2' ).value = true;
+
+				expect( listView.items.map( item => item.isActive ) ).to.deep.equal( [
+					false,
+					false,
+					true,
+					false
+				] );
+			} );
 		} );
 	} );
 } );