From 571310b999723b2164568b0299ef8a127416968e Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Thu, 6 Jul 2017 12:43:26 +0200 Subject: [PATCH 1/2] Fix: Keyboard listener should check if the command is enabled before opening the balloon. Closes #128. --- src/link.js | 6 +++++- tests/link.js | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/link.js b/src/link.js index ee1576a..6e06220 100644 --- a/src/link.js +++ b/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 ); diff --git a/tests/link.js b/tests/link.js index 4a10ae2..0a26940 100644 --- a/tests/link.js +++ b/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 ); } ); From 5d8d550a26d35d030317842e32297fa7ce7b18f3 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Thu, 6 Jul 2017 12:46:32 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Code=20refactoring:=20re=E2=80=93formatted?= =?UTF-8?q?=20the=20keystrokes=20to=20match=20the=20general=20code?= =?UTF-8?q?=E2=80=93style=20rules.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/link.js | 6 ++++-- tests/link.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/link.js b/src/link.js index 6e06220..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,7 @@ export default class Link extends Plugin { const t = editor.t; // Handle `Ctrl+K` keystroke and show the panel. - editor.keystrokes.set( 'CTRL+K', () => { + editor.keystrokes.set( linkKeystroke, () => { if ( linkCommand.isEnabled ) { this._showPanel( true ); } @@ -136,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 0a26940..4b302d8 100644 --- a/tests/link.js +++ b/tests/link.js @@ -437,7 +437,7 @@ 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' );