Browse Source

Fix: Keyboard listener should check if the command is enabled before opening the balloon. Closes #128.

Aleksander Nowodzinski 8 years ago
parent
commit
b9a0f00b8a
2 changed files with 11 additions and 1 deletions
  1. 5 1
      packages/ckeditor5-link/src/link.js
  2. 6 0
      packages/ckeditor5-link/tests/link.js

+ 5 - 1
packages/ckeditor5-link/src/link.js

@@ -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 );

+ 6 - 0
packages/ckeditor5-link/tests/link.js

@@ -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 );
 		} );