diff --git a/src/link.js b/src/link.js index ee1576a..e8543bb 100644 --- a/src/link.js +++ b/src/link.js @@ -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 Ctrl+K keystroke. * @@ -124,7 +126,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( linkKeystroke, () => { + if ( linkCommand.isEnabled ) { + this._showPanel( true ); + } + } ); editor.ui.componentFactory.add( 'link', locale => { const button = new ButtonView( locale ); @@ -132,7 +138,7 @@ export default class Link extends Plugin { 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. diff --git a/tests/link.js b/tests/link.js index 4a10ae2..4b302d8 100644 --- a/tests/link.js +++ b/tests/link.js @@ -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 ); } );