From e49780046e48c07c1b37d672f9d94a6904f4761d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Tue, 13 Jun 2017 09:31:04 +0200 Subject: [PATCH] Aligned command API usage to the changes done in ckeditor5-core#89. --- src/delete.js | 4 ++-- src/deletecommand.js | 5 +++-- src/input.js | 2 +- src/inputcommand.js | 26 +++++++++++++------------- tests/changebuffer.js | 2 +- tests/deletecommand-integration.js | 2 +- tests/deletecommand.js | 6 +++--- tests/inputcommand.js | 5 ++--- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/delete.js b/src/delete.js index 80da4b2..8904633 100644 --- a/src/delete.js +++ b/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 } ); diff --git a/src/deletecommand.js b/src/deletecommand.js index eb63577..4d4e9d1 100644 --- a/src/deletecommand.js +++ b/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; diff --git a/src/input.js b/src/input.js index fb1097c..26651e2 100644 --- a/src/input.js +++ b/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 ); diff --git a/src/inputcommand.js b/src/inputcommand.js index 0435499..bb8f6e5 100644 --- a/src/inputcommand.js +++ b/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 { /** @@ -36,16 +36,6 @@ export default class InputCommand extends Command { this._buffer = new ChangeBuffer( editor.document, undoStepSize ); } - /** - * @inheritDoc - */ - destroy() { - super.destroy(); - - this._buffer.destroy(); - this._buffer = null; - } - /** * The current change buffer. * @@ -55,11 +45,21 @@ export default class InputCommand extends Command { return this._buffer; } + /** + * @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; diff --git a/tests/changebuffer.js b/tests/changebuffer.js index 2ee5a7a..4092516 100644 --- a/tests/changebuffer.js +++ b/tests/changebuffer.js @@ -230,7 +230,7 @@ describe( 'ChangeBuffer', () => { } ); } ); - describe( 'destroy', () => { + describe( 'destroy()', () => { it( 'offs the buffer from the document', () => { const batch1 = buffer.batch; diff --git a/tests/deletecommand-integration.js b/tests/deletecommand-integration.js index 83d674d..3ded274 100644 --- a/tests/deletecommand-integration.js +++ b/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' ); diff --git a/tests/deletecommand.js b/tests/deletecommand.js index 897ce5b..1727c8c 100644 --- a/tests/deletecommand.js +++ b/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, '

foo[]bar

' ); @@ -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' ); } ); diff --git a/tests/inputcommand.js b/tests/inputcommand.js index 6891cf3..5dc4bcb 100644 --- a/tests/inputcommand.js +++ b/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, '

foo[]bar

' ); @@ -231,7 +231,6 @@ describe( 'InputCommand', () => { command.destroy(); expect( destroy.calledOnce ).to.be.true; - expect( command._buffer ).to.be.null; } ); } ); } );