Explorar o código

Fix: The default dropdown label should not equal 'Paragraph'. Closes #62.

Aleksander Nowodzinski %!s(int64=8) %!d(string=hai) anos
pai
achega
edc4cf92ea

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

@@ -39,7 +39,7 @@ export default class Heading extends Plugin {
 		const options = this._getLocalizedOptions();
 		const commands = [];
 		const t = editor.t;
-		let defaultOption;
+		const defaultTitle = t( 'Heading' );
 
 		for ( let option of options ) {
 			const command = editor.commands.get( option.modelElement );
@@ -55,17 +55,13 @@ export default class Heading extends Plugin {
 			dropdownItems.add( itemModel );
 
 			commands.push( command );
-
-			if ( !defaultOption && option.modelElement == 'paragraph' ) {
-				defaultOption = option;
-			}
 		}
 
 		// Create dropdown model.
 		const dropdownModel = new Model( {
 			withText: true,
 			items: dropdownItems,
-			tooltip: t( 'Heading' )
+			tooltip: defaultTitle
 		} );
 
 		dropdownModel.bind( 'isEnabled' ).to(
@@ -82,8 +78,8 @@ export default class Heading extends Plugin {
 			( ...areActive ) => {
 				const index = areActive.findIndex( value => value );
 
-				// If none of the commands is active, display the first one.
-				return ( options[ index ] || defaultOption ).title;
+				// If none of the commands is active, display default title.
+				return options[ index ] ? options[ index ].title : defaultTitle;
 			}
 		);
 

+ 8 - 2
packages/ckeditor5-heading/tests/heading.js

@@ -14,6 +14,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 add( 'pl', {
 	'Paragraph': 'Akapit',
+	'Heading': 'Nagłówek',
 	'Heading 1': 'Nagłówek 1',
 	'Heading 2': 'Nagłówek 2',
 } );
@@ -56,7 +57,7 @@ describe( 'Heading', () => {
 			expect( dropdown ).to.be.instanceOf( DropdownView );
 			expect( dropdown.buttonView.isEnabled ).to.be.true;
 			expect( dropdown.buttonView.isOn ).to.be.undefined;
-			expect( dropdown.buttonView.label ).to.equal( 'Paragraph' );
+			expect( dropdown.buttonView.label ).to.equal( 'Heading' );
 			expect( dropdown.buttonView.tooltip ).to.equal( 'Heading' );
 		} );
 
@@ -108,7 +109,7 @@ describe( 'Heading', () => {
 					commands[ name ].value = false;
 				}
 
-				expect( dropdown.buttonView.label ).to.equal( 'Paragraph' );
+				expect( dropdown.buttonView.label ).to.equal( 'Heading' );
 
 				commands.heading2.value = true;
 				expect( dropdown.buttonView.label ).to.equal( 'Heading 2' );
@@ -137,7 +138,12 @@ describe( 'Heading', () => {
 			it( 'works for the #buttonView', () => {
 				const buttonView = dropdown.buttonView;
 
+				expect( buttonView.label ).to.equal( 'Nagłówek' );
+
+				commands.paragraph.value = true;
 				expect( buttonView.label ).to.equal( 'Akapit' );
+
+				commands.paragraph.value = false;
 				commands.heading1.value = true;
 				expect( buttonView.label ).to.equal( 'Nagłówek 1' );
 			} );