diff --git a/lang/contexts.json b/lang/contexts.json index c894b84..3f53dce 100644 --- a/lang/contexts.json +++ b/lang/contexts.json @@ -1,6 +1,6 @@ { "Paragraph": "Drop-down option label for the paragraph format.", - "Heading": "Tooltip for the heading drop-down.", + "Heading": "Tooltip and default label for the heading drop-down.", "Heading 1": "Drop-down option label for the heading level 1 format.", "Heading 2": "Drop-down option label for the heading level 2 format.", "Heading 3": "Drop-down option label for the heading level 3 format." diff --git a/src/heading.js b/src/heading.js index b2f7aeb..96d1617 100644 --- a/src/heading.js +++ b/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; } ); diff --git a/tests/heading.js b/tests/heading.js index 92cc793..3dd1337 100644 --- a/tests/heading.js +++ b/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' ); } );