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 #133 from ckeditor/t/128
Browse files Browse the repository at this point in the history
Fix: Keyboard listener should check if the command is enabled before opening the balloon. Closes #128.
  • Loading branch information
oskarwrobel authored Jul 6, 2017
2 parents d58e200 + 5d8d550 commit be4b9eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import unlinkIcon from '../theme/icons/unlink.svg';

import '../theme/theme.scss';

const linkKeystroke = 'Ctrl+K';

/**
* The link plugin. It introduces the Link and Unlink buttons and the <kbd>Ctrl+K</kbd> keystroke.
*
Expand Down Expand Up @@ -124,15 +126,19 @@ export default class Link extends Plugin {
const t = editor.t;

// Handle `Ctrl+K` keystroke and show the panel.
editor.keystrokes.set( 'CTRL+K', () => this._showPanel( true ) );
editor.keystrokes.set( linkKeystroke, () => {
if ( linkCommand.isEnabled ) {
this._showPanel( true );
}
} );

editor.ui.componentFactory.add( 'link', locale => {
const button = new ButtonView( locale );

button.isEnabled = true;
button.label = t( 'Link' );
button.icon = linkIcon;
button.keystroke = 'CTRL+K';
button.keystroke = linkKeystroke;
button.tooltip = true;

// Bind button to the command.
Expand Down
8 changes: 7 additions & 1 deletion tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,15 @@ describe( 'Link', () => {
} );

describe( 'keyboard support', () => {
it( 'should show the #_balloon with selected #formView on `CTRL+K` keystroke', () => {
it( 'should show the #_balloon with selected #formView on Ctrl+K keystroke', () => {
const spy = testUtils.sinon.stub( linkFeature, '_showPanel', () => {} );
const command = editor.commands.get( 'link' );

command.isEnabled = false;
editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
sinon.assert.notCalled( spy );

command.isEnabled = true;
editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
sinon.assert.calledWithExactly( spy, true );
} );
Expand Down

0 comments on commit be4b9eb

Please sign in to comment.