Browse Source

Used EditingKeystrokeHandler in StandardEditor.

Aleksander Nowodzinski 9 years ago
parent
commit
753f8492ed

+ 5 - 2
packages/ckeditor5-core/src/editor/standardeditor.js

@@ -8,7 +8,7 @@
  */
 
 import Editor from './editor';
-import KeystrokeHandler from '../keystrokehandler';
+import EditingKeystrokeHandler from '../editingkeystrokehandler';
 import EditingController from 'ckeditor5-engine/src/controller/editingcontroller';
 
 import getDataFromElement from 'ckeditor5-utils/src/dom/getdatafromelement';
@@ -46,7 +46,7 @@ export default class StandardEditor extends Editor {
 		 * @readonly
 		 * @member {module:core/keystrokehandler~KeystrokeHandler}
 		 */
-		this.keystrokes = new KeystrokeHandler( this );
+		this.keystrokes = new EditingKeystrokeHandler( this );
 
 		/**
 		 * Editor UI instance.
@@ -58,6 +58,8 @@ export default class StandardEditor extends Editor {
 		 * @readonly
 		 * @member {module:core/editor/editorui~EditorUI} #ui
 		 */
+
+		this.keystrokes.listenTo( this.editing.view );
 	}
 
 	/**
@@ -65,6 +67,7 @@ export default class StandardEditor extends Editor {
 	 */
 	destroy() {
 		return Promise.resolve()
+			.then( () => this.keystrokes.destroy() )
 			.then( () => this.editing.destroy() )
 			.then( super.destroy() );
 	}

+ 23 - 2
packages/ckeditor5-core/tests/editor/standardeditor.js

@@ -10,7 +10,7 @@ import HtmlDataProcessor from 'ckeditor5-engine/src/dataprocessor/htmldataproces
 import { getData, setData } from 'ckeditor5-engine/src/dev-utils/model';
 
 import EditingController from 'ckeditor5-engine/src/controller/editingcontroller';
-import KeystrokeHandler from 'ckeditor5-core/src/keystrokehandler';
+import EditingKeystrokeHandler from 'ckeditor5-core/src/editingkeystrokehandler';
 import Plugin from 'ckeditor5-core/src/plugin';
 
 describe( 'StandardEditor', () => {
@@ -27,7 +27,14 @@ describe( 'StandardEditor', () => {
 
 			expect( editor ).to.have.property( 'element', editorElement );
 			expect( editor.editing ).to.be.instanceof( EditingController );
-			expect( editor.keystrokes ).to.be.instanceof( KeystrokeHandler );
+			expect( editor.keystrokes ).to.be.instanceof( EditingKeystrokeHandler );
+		} );
+
+		it( 'activates #keystrokes', () => {
+			const spy = sinon.spy( EditingKeystrokeHandler.prototype, 'listenTo' );
+			const editor = new StandardEditor( editorElement, { foo: 1 } );
+
+			sinon.assert.calledWith( spy, editor.editing.view );
 		} );
 
 		it( 'sets config', () => {
@@ -37,6 +44,20 @@ describe( 'StandardEditor', () => {
 		} );
 	} );
 
+	describe( 'destroy()', () => {
+		it( 'destroys the #keystrokes', () => {
+			const editor = new StandardEditor( editorElement, { foo: 1 } );
+			const spy = sinon.spy( editor.keystrokes, 'destroy' );
+
+			sinon.assert.notCalled( spy );
+
+			return editor.destroy()
+				.then( () => {
+					sinon.assert.calledOnce( spy );
+				} );
+		} );
+	} );
+
 	describe( 'create', () => {
 		it( 'initializes editor with plugins and config', () => {
 			class PluginFoo extends Plugin {}