浏览代码

Made sure the balloon closes on esc key press when either editable or any LinkFormView child is focused.

Aleksander Nowodzinski 9 年之前
父节点
当前提交
23bba46296
共有 2 个文件被更改,包括 21 次插入2 次删除
  1. 7 1
      packages/ckeditor5-link/src/link.js
  2. 14 1
      packages/ckeditor5-link/tests/link.js

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

@@ -175,7 +175,7 @@ export default class Link extends Plugin {
 			}
 		} );
 
-		// // Close the panel on esc key press.
+		// Close the panel on esc key press when editable has focus.
 		editor.keystrokes.set( 'esc', ( data, cancel ) => {
 			if ( balloonPanelView.isVisible ) {
 				this._hidePanel( true );
@@ -220,6 +220,12 @@ export default class Link extends Plugin {
 			this._hidePanel( true );
 		} );
 
+		// Close the panel on esc key press when the form has focus.
+		formView.keystrokes.set( 'esc', ( data, cancel ) => {
+			this._hidePanel( true );
+			cancel();
+		} );
+
 		// Hide balloon panel after clicking on formView `Cancel` button.
 		this.listenTo( formView, 'cancel', () => this._hidePanel( true ) );
 

+ 14 - 1
packages/ckeditor5-link/tests/link.js

@@ -222,7 +222,7 @@ describe( 'Link', () => {
 
 		describe( 'close listeners', () => {
 			describe( 'keyboard', () => {
-				it( 'should close after `ESC` press', () => {
+				it( 'should close after esc key press (from editor)', () => {
 					const keyEvtData = {
 						keyCode: keyCodes.esc,
 						preventDefault: sinon.spy(),
@@ -243,6 +243,19 @@ describe( 'Link', () => {
 					sinon.assert.calledOnce( hidePanelSpy );
 					sinon.assert.calledOnce( focusEditableSpy );
 				} );
+
+				it( 'should close after esc key press (from the form)', () => {
+					const keyEvtData = {
+						keyCode: keyCodes.esc,
+						preventDefault: sinon.spy(),
+						stopPropagation: sinon.spy()
+					};
+
+					formView.keystrokes.press( keyEvtData );
+
+					sinon.assert.calledOnce( hidePanelSpy );
+					sinon.assert.calledOnce( focusEditableSpy );
+				} );
 			} );
 
 			describe( 'mouse', () => {