浏览代码

Other: Aligned the implementation to the new Command API (see https://github.com/ckeditor/ckeditor5-core/issues/88).

BREAKING CHANGES: The command API has been changed.
Szymon Kupś 8 年之前
父节点
当前提交
1993adf1e1

+ 2 - 2
packages/ckeditor5-typing/src/delete.js

@@ -30,8 +30,8 @@ export default class Delete extends Plugin {
 
 		editingView.addObserver( DeleteObserver );
 
-		editor.commands.set( 'forwardDelete', new DeleteCommand( editor, 'forward' ) );
-		editor.commands.set( 'delete', new DeleteCommand( editor, 'backward' ) );
+		editor.commands.add( 'forwardDelete', new DeleteCommand( editor, 'forward' ) );
+		editor.commands.add( 'delete', new DeleteCommand( editor, 'backward' ) );
 
 		this.listenTo( editingView, 'delete', ( evt, data ) => {
 			editor.execute( data.direction == 'forward' ? 'forwardDelete' : 'delete', { unit: data.unit } );

+ 3 - 2
packages/ckeditor5-typing/src/deletecommand.js

@@ -7,7 +7,7 @@
  * @module typing/deletecommand
  */
 
-import Command from '@ckeditor/ckeditor5-core/src/command/command';
+import Command from '@ckeditor/ckeditor5-core/src/command';
 import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
 import ChangeBuffer from './changebuffer';
 import count from '@ckeditor/ckeditor5-utils/src/count';
@@ -52,11 +52,12 @@ export default class DeleteCommand extends Command {
 	 * Executes the delete command. Depending on whether the selection is collapsed or not, deletes its content
 	 * or a piece of content in the {@link #direction defined direction}.
 	 *
+	 * @fires execute
 	 * @param {Object} [options] The command options.
 	 * @param {'character'} [options.unit='character'] See {@link module:engine/controller/modifyselection~modifySelection}'s
 	 * options.
 	 */
-	_doExecute( options = {} ) {
+	execute( options = {} ) {
 		const doc = this.editor.document;
 		const dataController = this.editor.data;
 

+ 1 - 1
packages/ckeditor5-typing/src/input.js

@@ -39,7 +39,7 @@ export default class Input extends Plugin {
 
 		// TODO The above default configuration value should be defined using editor.config.define() once it's fixed.
 
-		editor.commands.set( 'input', inputCommand );
+		editor.commands.add( 'input', inputCommand );
 
 		this.listenTo( editingView, 'keydown', ( evt, data ) => {
 			this._handleKeydown( data, inputCommand.buffer );

+ 13 - 13
packages/ckeditor5-typing/src/inputcommand.js

@@ -7,13 +7,13 @@
  * @module typing/inputcommand
  */
 
-import Command from '@ckeditor/ckeditor5-core/src/command/command';
+import Command from '@ckeditor/ckeditor5-core/src/command';
 import ChangeBuffer from './changebuffer';
 
 /**
  * The input command. Used by the {@link module:typing/input~Input input feature} to handle typing.
  *
- * @extends module:core/command/command~Command
+ * @extends module:core/command~Command
  */
 export default class InputCommand extends Command {
 	/**
@@ -37,16 +37,6 @@ export default class InputCommand extends Command {
 	}
 
 	/**
-	 * @inheritDoc
-	 */
-	destroy() {
-		super.destroy();
-
-		this._buffer.destroy();
-		this._buffer = null;
-	}
-
-	/**
 	 * The current change buffer.
 	 *
 	 * @type {module:typing/changebuffer~ChangeBuffer}
@@ -56,10 +46,20 @@ export default class InputCommand extends Command {
 	}
 
 	/**
+	 * @inheritDoc
+	 */
+	destroy() {
+		super.destroy();
+
+		this._buffer.destroy();
+	}
+
+	/**
 	 * Executes the input command. It replaces the content within the given range with the given text.
 	 * Replacing is a two step process, first content within the range is removed and then new text is inserted
 	 * on the beginning of the range (which after removal is a collapsed range).
 	 *
+	 * @fires execute
 	 * @param {Object} [options] The command options.
 	 * @param {String} [options.text=''] Text to be inserted.
 	 * @param {module:engine/model/range~Range} [options.range] Range in which the text is inserted. Defaults
@@ -68,7 +68,7 @@ export default class InputCommand extends Command {
 	 * should be placed after the insertion. If not specified, the selection will be placed right after
 	 * the inserted text.
 	 */
-	_doExecute( options = {} ) {
+	execute( options = {} ) {
 		const doc = this.editor.document;
 		const text = options.text || '';
 		const textInsertions = text.length;

+ 1 - 1
packages/ckeditor5-typing/tests/changebuffer.js

@@ -230,7 +230,7 @@ describe( 'ChangeBuffer', () => {
 		} );
 	} );
 
-	describe( 'destroy', () => {
+	describe( 'destroy()', () => {
 		it( 'offs the buffer from the document', () => {
 			const batch1 = buffer.batch;
 

+ 1 - 1
packages/ckeditor5-typing/tests/deletecommand-integration.js

@@ -18,7 +18,7 @@ describe( 'DeleteCommand integration', () => {
 				doc = editor.document;
 
 				const command = new DeleteCommand( editor, 'backward' );
-				editor.commands.set( 'delete', command );
+				editor.commands.add( 'delete', command );
 
 				doc.schema.registerItem( 'p', '$block' );
 				doc.schema.registerItem( 'img', '$inline' );

+ 3 - 3
packages/ckeditor5-typing/tests/deletecommand.js

@@ -20,7 +20,7 @@ describe( 'DeleteCommand', () => {
 				doc = editor.document;
 
 				const command = new DeleteCommand( editor, 'backward' );
-				editor.commands.set( 'delete', command );
+				editor.commands.add( 'delete', command );
 
 				doc.schema.registerItem( 'p', '$block' );
 			} );
@@ -36,7 +36,7 @@ describe( 'DeleteCommand', () => {
 		expect( command ).to.have.property( 'direction', 'forward' );
 	} );
 
-	describe( 'execute', () => {
+	describe( 'execute()', () => {
 		it( 'uses enqueueChanges', () => {
 			setData( doc, '<p>foo[]bar</p>' );
 
@@ -108,7 +108,7 @@ describe( 'DeleteCommand', () => {
 
 			expect( spy.callCount ).to.equal( 1 );
 
-			const modifyOpts = spy.args[ 0 ][ 1 ].options;
+			const modifyOpts = spy.args[ 0 ][ 1 ][ 1 ];
 			expect( modifyOpts ).to.have.property( 'direction', 'forward' );
 			expect( modifyOpts ).to.have.property( 'unit', 'word' );
 		} );

+ 2 - 3
packages/ckeditor5-typing/tests/inputcommand.js

@@ -25,7 +25,7 @@ describe( 'InputCommand', () => {
 				doc = editor.document;
 
 				const inputCommand = new InputCommand( editor, 20 );
-				editor.commands.set( 'input', inputCommand );
+				editor.commands.add( 'input', inputCommand );
 
 				buffer = inputCommand.buffer;
 
@@ -64,7 +64,7 @@ describe( 'InputCommand', () => {
 		} );
 	} );
 
-	describe( 'execute', () => {
+	describe( 'execute()', () => {
 		it( 'uses enqueueChanges', () => {
 			setData( doc, '<p>foo[]bar</p>' );
 
@@ -231,7 +231,6 @@ describe( 'InputCommand', () => {
 			command.destroy();
 
 			expect( destroy.calledOnce ).to.be.true;
-			expect( command._buffer ).to.be.null;
 		} );
 	} );
 } );