Przeglądaj źródła

Merge pull request #155 from ckeditor/t/153

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.
Piotrek Koszuliński 8 lat temu
rodzic
commit
e06e5c453b

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

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

+ 27 - 2
packages/ckeditor5-link/tests/link.js

@@ -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,