Bläddra i källkod

Some integration proposals for core.Editor.

Szymon Cofalik 9 år sedan
förälder
incheckning
ccb68c6934

+ 23 - 0
packages/ckeditor5-engine/src/editor.js

@@ -8,6 +8,8 @@
 import ObservableMixin from './observablemixin.js';
 import EditorConfig from './editorconfig.js';
 import PluginCollection from './plugincollection.js';
+import Document from './treemodel/document.js';
+import Mapper from './treecontroller/mapper.js';
 import CKEditorError from './ckeditorerror.js';
 import Locale from './locale.js';
 import isArray from './lib/lodash/isArray.js';
@@ -59,6 +61,12 @@ export default class Editor {
 		 */
 		this.plugins = new PluginCollection( this );
 
+		this.document = new Document();
+
+		this.commands = new Map();
+
+		this.treeMapper = new Mapper();
+
 		/**
 		 * @readonly
 		 * @member {core.Locale} core.Editor#locale
@@ -172,6 +180,21 @@ export default class Editor {
 	getData() {
 		return this.editable.getData();
 	}
+
+	execute( commandName ) {
+		let command = this.commands.get( commandName );
+
+		if ( !command ) {
+			/**
+			 * Specified command has not been added to the editor.
+			 *
+			 * @error editor-command-not-found
+			 */
+			throw new CKEditorError( 'editor-command-not-found: Specified command has not been added to the editor.' );
+		}
+
+		command.execute();
+	}
 }
 
 utils.mix( Editor, ObservableMixin );

+ 24 - 0
packages/ckeditor5-engine/tests/editor/editor.js

@@ -13,6 +13,8 @@ import Editor from '/ckeditor5/core/editor.js';
 import EditorConfig from '/ckeditor5/core/editorconfig.js';
 import Plugin from '/ckeditor5/core/plugin.js';
 import Locale from '/ckeditor5/core/locale.js';
+import Command from '/ckeditor5/core/command.js';
+import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
 
 const pluginClasses = {};
 let element;
@@ -197,6 +199,28 @@ describe( 'destroy', () => {
 	} );
 } );
 
+describe( 'execute', () => {
+	it( 'should execute specified command', () => {
+		const editor = new Editor( element );
+
+		let command = new Command( editor );
+		sinon.spy( command, 'execute' );
+
+		editor.commands.set( 'command_name', command );
+		editor.execute( 'command_name' );
+
+		expect( command.execute.calledOnce ).to.be.true;
+	} );
+
+	it( 'should throw an error if specified command has not been added', () => {
+		const editor = new Editor( element );
+
+		expect( () => {
+			editor.execute( 'command' );
+		} ).to.throw( CKEditorError, /editor-command-not-found/ );
+	} );
+} );
+
 describe( 'setData', () => {
 	it( 'should set data on the editable', () => {
 		const editor = new Editor( element );