8
0
Просмотр исходного кода

Use editor.keystrokes nad editor.ui.view.toolbar.keystrokes instead of editor.ui.keystrokes.

Aleksander Nowodzinski 9 лет назад
Родитель
Сommit
b0c6ecc13a

+ 2 - 24
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -9,7 +9,6 @@
 
 import ComponentFactory from '@ckeditor/ckeditor5-ui/src/componentfactory';
 import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
-import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
 
 /**
  * The classic editor UI class.
@@ -54,21 +53,6 @@ export default class ClassicEditorUI {
 		 */
 		this.focusTracker = new FocusTracker();
 
-		/**
-		 * Instance of the {@link module:core/keystrokehandler~KeystrokeHandler}.
-		 *
-		 * Unlike {@link core/editor/standardeditor~StandardEditor#keystrokes}, this
-		 * keystroke handler is focused on keystrokes associated exclusively with the
-		 * user interface, not edited content. It takes care of accessibility–related
-		 * keystrokes (e.g. focus the toolbar) and similar, leaving content
-		 * keystrokes (e.g. bold text, insert link) to aforementioned instance
-		 * in `StandardEditor`.
-		 *
-		 * @readonly
-		 * @member {module:core/keystrokehandler~KeystrokeHandler}
-		 */
-		this.keystrokes = new KeystrokeHandler();
-
 		// Set–up the view.
 		view.set( 'width', editor.config.get( 'ui.width' ) );
 		view.set( 'height', editor.config.get( 'ui.height' ) );
@@ -113,14 +97,8 @@ export default class ClassicEditorUI {
 				// the toolbar must also be tracked.
 				this.focusTracker.add( this.view.toolbar.element );
 
-				// Listen on the keystrokes from the main UI.
-				this.keystrokes.listenTo( this.view.element );
-
-				// Listen on the keystrokes from the floating panels, toolbars and the such.
-				this.keystrokes.listenTo( this.view._bodyCollectionContainer );
-
 				// Focus the toolbar on the keystroke, if not already focused.
-				this.keystrokes.set( 'alt + f10', ( data, cancel ) => {
+				editor.keystrokes.set( 'alt + f10', ( data, cancel ) => {
 					if ( this.focusTracker.isFocused && !toolbarFocusTracker.isFocused ) {
 						this.view.toolbar.focus();
 						cancel();
@@ -128,7 +106,7 @@ export default class ClassicEditorUI {
 				} );
 
 				// Blur the toolbar and bring the focus back to editable on the keystroke.
-				this.keystrokes.set( 'esc', ( data, cancel ) => {
+				this.view.toolbar.keystrokes.set( 'esc', ( data, cancel ) => {
 					if ( toolbarFocusTracker.isFocused ) {
 						editor.editing.view.focus();
 						cancel();

+ 5 - 20
packages/ckeditor5-editor-classic/tests/classiceditorui.js

@@ -13,7 +13,6 @@ import ClassicEditorUIView from '../src/classiceditoruiview';
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 
 import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
-import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
@@ -61,10 +60,6 @@ describe( 'ClassicEditorUI', () => {
 			expect( ui.focusTracker ).to.be.instanceOf( FocusTracker );
 		} );
 
-		it( 'creates #keystrokes', () => {
-			expect( ui.keystrokes ).to.be.instanceOf( KeystrokeHandler );
-		} );
-
 		it( 'sets view#width and view#height', () => {
 			expect( view.width ).to.equal( 100 );
 			expect( view.height ).to.equal( 200 );
@@ -152,16 +147,6 @@ describe( 'ClassicEditorUI', () => {
 		} );
 
 		describe( 'activates keyboard navigation for the toolbar', () => {
-			it( 'listens for keystrokes coming from various parts of the UI', () => {
-				const spy = sinon.spy( ui.keystrokes, 'listenTo' );
-
-				return ui.init().then( () => {
-					sinon.assert.calledTwice( spy );
-					sinon.assert.calledWithExactly( spy.firstCall, ui.view.element );
-					sinon.assert.calledWithExactly( spy.secondCall, ui.view._bodyCollectionContainer );
-				} );
-			} );
-
 			it( 'alt + f10: focus the first focusable toolbar item', () => {
 				return ui.init().then( () => {
 					const spy = sinon.spy( view.toolbar, 'focus' );
@@ -176,19 +161,19 @@ describe( 'ClassicEditorUI', () => {
 					toolbarFocusTracker.isFocused = false;
 					ui.focusTracker.isFocused = false;
 
-					ui.keystrokes.press( keyEvtData );
+					editor.keystrokes.press( keyEvtData );
 					sinon.assert.notCalled( spy );
 
 					toolbarFocusTracker.isFocused = true;
 					ui.focusTracker.isFocused = true;
 
-					ui.keystrokes.press( keyEvtData );
+					editor.keystrokes.press( keyEvtData );
 					sinon.assert.notCalled( spy );
 
 					toolbarFocusTracker.isFocused = false;
 					ui.focusTracker.isFocused = true;
 
-					ui.keystrokes.press( keyEvtData );
+					editor.keystrokes.press( keyEvtData );
 					sinon.assert.calledOnce( spy );
 
 					sinon.assert.calledOnce( keyEvtData.preventDefault );
@@ -207,12 +192,12 @@ describe( 'ClassicEditorUI', () => {
 
 					toolbarFocusTracker.isFocused = false;
 
-					ui.keystrokes.press( keyEvtData );
+					ui.view.toolbar.keystrokes.press( keyEvtData );
 					sinon.assert.notCalled( spy );
 
 					toolbarFocusTracker.isFocused = true;
 
-					ui.keystrokes.press( keyEvtData );
+					ui.view.toolbar.keystrokes.press( keyEvtData );
 
 					sinon.assert.calledOnce( spy );
 					sinon.assert.calledOnce( keyEvtData.preventDefault );