浏览代码

Merge pull request #133 from ckeditor/t/128

Fix: Keyboard listener should check if the command is enabled before opening the balloon. Closes #128.
Oskar Wróbel 8 年之前
父节点
当前提交
315dd63b7a
共有 2 个文件被更改,包括 15 次插入3 次删除
  1. 8 2
      packages/ckeditor5-link/src/link.js
  2. 7 1
      packages/ckeditor5-link/tests/link.js

+ 8 - 2
packages/ckeditor5-link/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 <kbd>Ctrl+K</kbd> 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.

+ 7 - 1
packages/ckeditor5-link/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 );
 		} );