8
0
فهرست منبع

Changed: Update dropdown API usage.

Maciej Gołaszewski 8 سال پیش
والد
کامیت
a35c12b019
2فایلهای تغییر یافته به همراه20 افزوده شده و 20 حذف شده
  1. 11 11
      packages/ckeditor5-highlight/src/highlightui.js
  2. 9 9
      packages/ckeditor5-highlight/tests/highlightui.js

+ 11 - 11
packages/ckeditor5-highlight/src/highlightui.js

@@ -176,10 +176,10 @@ export default class HighlightUI extends Plugin {
 
 		componentFactory.add( 'highlightDropdown', locale => {
 			const command = editor.commands.get( 'highlight' );
-
 			const dropdownView = createDropdown( locale, SplitButtonView );
+			const splitButtonView = dropdownView.buttonView;
 
-			dropdownView.buttonView.set( {
+			splitButtonView.set( {
 				tooltip: t( 'Highlight' ),
 				// Holds last executed highlighter.
 				lastExecuted: startingHighlighter.model,
@@ -190,14 +190,14 @@ export default class HighlightUI extends Plugin {
 			// Dropdown button changes to selection (command.value):
 			// - If selection is in highlight it get active highlight appearance (icon, color) and is activated.
 			// - Otherwise it gets appearance (icon, color) of last executed highlight.
-			dropdownView.buttonView.bind( 'icon' ).to( command, 'value', value => getIconForType( getActiveOption( value, 'type' ) ) );
-			dropdownView.buttonView.bind( 'color' ).to( command, 'value', value => getActiveOption( value, 'color' ) );
-			dropdownView.buttonView.bind( 'commandValue' ).to( command, 'value', value => getActiveOption( value, 'model' ) );
-			dropdownView.buttonView.bind( 'isOn' ).to( command, 'value', value => !!value );
+			splitButtonView.bind( 'icon' ).to( command, 'value', value => getIconForType( getActiveOption( value, 'type' ) ) );
+			splitButtonView.bind( 'color' ).to( command, 'value', value => getActiveOption( value, 'color' ) );
+			splitButtonView.bind( 'commandValue' ).to( command, 'value', value => getActiveOption( value, 'model' ) );
+			splitButtonView.bind( 'isOn' ).to( command, 'value', value => !!value );
 
-			dropdownView.buttonView.delegate( 'execute' ).to( dropdownView );
+			splitButtonView.delegate( 'execute' ).to( dropdownView );
 
-			dropdownView.buttonView.extendTemplate( {
+			splitButtonView.extendTemplate( {
 				attributes: {
 					class: 'ck-highlight-button'
 				}
@@ -232,8 +232,8 @@ export default class HighlightUI extends Plugin {
 			} );
 
 			// Execute current action from dropdown's split button action button.
-			dropdownView.on( 'execute', () => {
-				editor.execute( 'highlight', { value: dropdownView.commandValue } );
+			splitButtonView.on( 'execute', () => {
+				editor.execute( 'highlight', { value: splitButtonView.commandValue } );
 				editor.editing.view.focus();
 			} );
 
@@ -242,7 +242,7 @@ export default class HighlightUI extends Plugin {
 			// of last executed highlighter. Otherwise it will return option key for current one.
 			function getActiveOption( current, key ) {
 				const whichHighlighter = !current ||
-				current === dropdownView.buttonView.lastExecuted ? dropdownView.buttonView.lastExecuted : current;
+				current === splitButtonView.lastExecuted ? splitButtonView.lastExecuted : current;
 
 				return optionsMap[ whichHighlighter ][ key ];
 			}

+ 9 - 9
packages/ckeditor5-highlight/tests/highlightui.js

@@ -91,15 +91,6 @@ describe( 'HighlightUI', () => {
 				.to.deep.equal( [ true, true, true, true, true, false, false ] );
 		} );
 
-		it( 'should focus view after command execution', () => {
-			const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
-
-			dropdown.commandName = 'highlight';
-			dropdown.fire( 'execute' );
-
-			sinon.assert.calledOnce( focusSpy );
-		} );
-
 		it( 'should have proper icons in dropdown', () => {
 			const toolbar = dropdown.toolbarView;
 
@@ -166,6 +157,15 @@ describe( 'HighlightUI', () => {
 
 				validateButton( 4 );
 			} );
+
+			it( 'should focus view after command execution', () => {
+				const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
+
+				dropdown.buttonView.commandName = 'highlight';
+				dropdown.buttonView.fire( 'execute' );
+
+				sinon.assert.calledOnce( focusSpy );
+			} );
 		} );
 
 		describe( 'model to command binding', () => {