Selaa lähdekoodia

Moved EditingKeystrokeHandler from StandardEditor to Editor.

Oskar Wróbel 8 vuotta sitten
vanhempi
sitoutus
f57d65734b

+ 14 - 2
packages/ckeditor5-core/src/editor/editor.js

@@ -14,14 +14,16 @@ import CommandCollection from '../commandcollection';
 import Locale from '@ckeditor/ckeditor5-utils/src/locale';
 import DataController from '@ckeditor/ckeditor5-engine/src/controller/datacontroller';
 import Model from '@ckeditor/ckeditor5-engine/src/model/model';
+import EditingKeystrokeHandler from '../editingkeystrokehandler';
 
 import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 
 /**
  * Class representing editor. It contains basic editor architecture and provides API needed by plugins
- * like {@link module:engine/controller/editingcontroller~EditingController editing pipeline} and
- * {@link module:engine/controller/datacontroller~DataController data pipeline}.
+ * like {@link module:engine/controller/editingcontroller~EditingController editing pipeline},
+ * {@link module:engine/controller/datacontroller~DataController data pipeline} and
+ * {module:core/editingkeystrokehandler~EditingKeystrokeHandler keystroke handler}.
  *
  * Besides it creates main {@link module:engine/model/rootelement~RootElement} using
  * {@link module:engine/model/document~Document#createRoot createRoot} method what automatically creates
@@ -122,6 +124,15 @@ export default class Editor {
 		 */
 		this.editing = new EditingController( this.model );
 		this.editing.view.bind( 'isReadOnly' ).to( this );
+
+		/**
+		 * Instance of the {@link module:core/editingkeystrokehandler~EditingKeystrokeHandler}.
+		 *
+		 * @readonly
+		 * @member {module:core/editingkeystrokehandler~EditingKeystrokeHandler}
+		 */
+		this.keystrokes = new EditingKeystrokeHandler( this );
+		this.keystrokes.listenTo( this.editing.view );
 	}
 
 	/**
@@ -176,6 +187,7 @@ export default class Editor {
 				this.model.destroy();
 				this.data.destroy();
 				this.editing.destroy();
+				this.keystrokes.destroy();
 			} );
 	}
 

+ 1 - 21
packages/ckeditor5-core/src/editor/standardeditor.js

@@ -8,14 +8,13 @@
  */
 
 import Editor from './editor';
-import EditingKeystrokeHandler from '../editingkeystrokehandler';
 import isFunction from '@ckeditor/ckeditor5-utils/src/lib/lodash/isFunction';
 
 import getDataFromElement from '@ckeditor/ckeditor5-utils/src/dom/getdatafromelement';
 import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement';
 
 /**
- * Class representing a typical browser-based editor.
+ * Class provides API methods for getting and setting data.
  *
  * @extends module:core/editor/editor~Editor
  */
@@ -38,14 +37,6 @@ export default class StandardEditor extends Editor {
 		 */
 		this.element = element;
 
-		/**
-		 * Instance of the {@link module:core/editingkeystrokehandler~EditingKeystrokeHandler}.
-		 *
-		 * @readonly
-		 * @member {module:core/editingkeystrokehandler~EditingKeystrokeHandler}
-		 */
-		this.keystrokes = new EditingKeystrokeHandler( this );
-
 		/**
 		 * Editor UI instance.
 		 *
@@ -57,20 +48,9 @@ export default class StandardEditor extends Editor {
 		 * @member {module:core/editor/editorui~EditorUI} #ui
 		 */
 
-		this.keystrokes.listenTo( this.editing.view );
-
 		this._attachToForm();
 	}
 
-	/**
-	 * @inheritDoc
-	 */
-	destroy() {
-		return Promise.resolve()
-			.then( () => this.keystrokes.destroy() )
-			.then( super.destroy() );
-	}
-
 	/**
 	 * Sets the data in the editor's main root.
 	 *

+ 19 - 8
packages/ckeditor5-core/tests/editor/editor.js

@@ -14,6 +14,7 @@ import CommandCollection from '../../src/commandcollection';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Locale from '@ckeditor/ckeditor5-utils/src/locale';
 import Command from '../../src/command';
+import EditingKeystrokeHandler from '../../src/editingkeystrokehandler';
 
 class PluginA extends Plugin {
 	constructor( editor ) {
@@ -105,6 +106,7 @@ describe( 'Editor', () => {
 			expect( editor.config ).to.be.an.instanceof( Config );
 			expect( editor.commands ).to.be.an.instanceof( CommandCollection );
 			expect( editor.editing ).to.be.instanceof( EditingController );
+			expect( editor.keystrokes ).to.be.instanceof( EditingKeystrokeHandler );
 
 			expect( editor.plugins ).to.be.an.instanceof( PluginCollection );
 			expect( getPlugins( editor ) ).to.be.empty;
@@ -153,6 +155,13 @@ describe( 'Editor', () => {
 
 			expect( editor.model.document.hasRoot( 'main' ) ).to.true;
 		} );
+
+		it( 'should activate #keystrokes', () => {
+			const spy = sinon.spy( EditingKeystrokeHandler.prototype, 'listenTo' );
+			const editor = new Editor();
+
+			sinon.assert.calledWith( spy, editor.editing.view );
+		} );
 	} );
 
 	describe( 'plugins', () => {
@@ -212,17 +221,19 @@ describe( 'Editor', () => {
 		it( 'should destroy all components it initialized', () => {
 			const editor = new Editor();
 
-			const spy1 = sinon.spy( editor.data, 'destroy' );
-			const spy2 = sinon.spy( editor.model, 'destroy' );
-			const spy3 = sinon.spy( editor.editing, 'destroy' );
-			const spy4 = sinon.spy( editor.plugins, 'destroy' );
+			const dataDestroySpy = sinon.spy( editor.data, 'destroy' );
+			const modelDestroySpy = sinon.spy( editor.model, 'destroy' );
+			const editingDestroySpy = sinon.spy( editor.editing, 'destroy' );
+			const pluginsDestroySpy = sinon.spy( editor.plugins, 'destroy' );
+			const keystrokesDestroySpy = sinon.spy( editor.keystrokes, 'destroy' );
 
 			return editor.destroy()
 				.then( () => {
-					expect( spy1.calledOnce ).to.be.true;
-					expect( spy2.calledOnce ).to.be.true;
-					expect( spy3.calledOnce ).to.be.true;
-					expect( spy4.calledOnce ).to.be.true;
+					sinon.assert.calledOnce( dataDestroySpy );
+					sinon.assert.calledOnce( modelDestroySpy );
+					sinon.assert.calledOnce( editingDestroySpy );
+					sinon.assert.calledOnce( pluginsDestroySpy );
+					sinon.assert.calledOnce( keystrokesDestroySpy );
 				} );
 		} );
 	} );

+ 0 - 21
packages/ckeditor5-core/tests/editor/standardeditor.js

@@ -10,7 +10,6 @@ import StandardEditor from '../../src/editor/standardeditor';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
-import EditingKeystrokeHandler from '../../src/editingkeystrokehandler';
 import Plugin from '../../src/plugin';
 
 describe( 'StandardEditor', () => {
@@ -26,14 +25,6 @@ describe( 'StandardEditor', () => {
 			const editor = new StandardEditor( editorElement, { foo: 1 } );
 
 			expect( editor ).to.have.property( 'element', editorElement );
-			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', () => {
@@ -50,18 +41,6 @@ describe( 'StandardEditor', () => {
 			expect( editor.destroy() ).to.be.an.instanceof( Promise );
 		} );
 
-		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 );
-				} );
-		} );
-
 		it( 'destroys the parent', () => {
 			const editor = new StandardEditor( editorElement, { foo: 1 } );
 			const spy = sinon.spy( Editor.prototype, 'destroy' );