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

Commit

Permalink
Fix: Keyboard listener should check if the command is enabled before …
Browse files Browse the repository at this point in the history
…opening the balloon. Closes #128.
  • Loading branch information
oleq committed Jul 6, 2017
1 parent d58e200 commit 571310b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ 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( 'CTRL+K', () => {
if ( linkCommand.isEnabled ) {
this._showPanel( true );
}
} );

editor.ui.componentFactory.add( 'link', locale => {
const button = new ButtonView( locale );
Expand Down
6 changes: 6 additions & 0 deletions tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,13 @@ describe( 'Link', () => {
describe( 'keyboard support', () => {
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 571310b

Please sign in to comment.