Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #64 from ckeditor/t/62
Browse files Browse the repository at this point in the history
Fix: The default dropdown label shows 'Heading'. Closes #62.
  • Loading branch information
szymonkups authored Mar 15, 2017
2 parents 1115bc7 + 88f5d5d commit e58dadc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lang/contexts.json
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
12 changes: 4 additions & 8 deletions src/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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(
Expand All @@ -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;
}
);

Expand Down
10 changes: 8 additions & 2 deletions tests/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
} );
Expand Down Expand Up @@ -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' );
} );

Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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' );
} );
Expand Down

0 comments on commit e58dadc

Please sign in to comment.