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

Commit

Permalink
Merge pull request #155 from ckeditor/t/153
Browse files Browse the repository at this point in the history
Fix: Prevented default browser actions on <kbd>Ctrl</kbd>+<kbd>K</kbd> (which should move focus to "URL" input in the link balloon. Closes #153. Closes #154.
  • Loading branch information
Reinmar authored Oct 2, 2017
2 parents e06f410 + deeb28b commit 5360fce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ export default class Link extends Plugin {
const t = editor.t;

// Handle the `Ctrl+K` keystroke and show the panel.
editor.keystrokes.set( linkKeystroke, () => {
editor.keystrokes.set( linkKeystroke, ( keyEvtData, cancel ) => {
// Prevent focusing the search bar in FF and opening new tab in Edge. #153, #154.
cancel();

if ( linkCommand.isEnabled ) {
this._showPanel( true );
}
Expand Down
29 changes: 27 additions & 2 deletions tests/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,39 @@ describe( 'Link', () => {
const command = editor.commands.get( 'link' );

command.isEnabled = false;
editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
editor.keystrokes.press( {
keyCode: keyCodes.k,
ctrlKey: true,
preventDefault: sinon.spy(),
stopPropagation: sinon.spy()
} );
sinon.assert.notCalled( spy );

command.isEnabled = true;
editor.keystrokes.press( { keyCode: keyCodes.k, ctrlKey: true } );
editor.keystrokes.press( {
keyCode: keyCodes.k,
ctrlKey: true,
preventDefault: sinon.spy(),
stopPropagation: sinon.spy()
} );
sinon.assert.calledWithExactly( spy, true );
} );

it( 'should prevent default action on Ctrl+K keystroke', () => {
const preventDefaultSpy = sinon.spy();
const stopPropagationSpy = sinon.spy();

editor.keystrokes.press( {
keyCode: keyCodes.k,
ctrlKey: true,
preventDefault: preventDefaultSpy,
stopPropagation: stopPropagationSpy
} );

sinon.assert.calledOnce( preventDefaultSpy );
sinon.assert.calledOnce( stopPropagationSpy );
} );

it( 'should focus the the #formView on `Tab` key press when the #_balloon is open', () => {
const keyEvtData = {
keyCode: keyCodes.tab,
Expand Down

0 comments on commit 5360fce

Please sign in to comment.