Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Other: Aligned the implementation to the new Command API (see https:/…
Browse files Browse the repository at this point in the history
…/github.com/ckeditor/ckeditor5-core/issues/88).

BREAKING CHANGES: The command API has been changed.
  • Loading branch information
szymonkups committed Jun 13, 2017
2 parents ee7ff41 + e497800 commit b241ac6
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
Expand Down
5 changes: 3 additions & 2 deletions src/deletecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
26 changes: 13 additions & 13 deletions src/inputcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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.
*
Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/changebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe( 'ChangeBuffer', () => {
} );
} );

describe( 'destroy', () => {
describe( 'destroy()', () => {
it( 'offs the buffer from the document', () => {
const batch1 = buffer.batch;

Expand Down
2 changes: 1 addition & 1 deletion tests/deletecommand-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
6 changes: 3 additions & 3 deletions tests/deletecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
} );
Expand All @@ -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>' );

Expand Down Expand Up @@ -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' );
} );
Expand Down
5 changes: 2 additions & 3 deletions tests/inputcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -64,7 +64,7 @@ describe( 'InputCommand', () => {
} );
} );

describe( 'execute', () => {
describe( 'execute()', () => {
it( 'uses enqueueChanges', () => {
setData( doc, '<p>foo[]bar</p>' );

Expand Down Expand Up @@ -231,7 +231,6 @@ describe( 'InputCommand', () => {
command.destroy();

expect( destroy.calledOnce ).to.be.true;
expect( command._buffer ).to.be.null;
} );
} );
} );

0 comments on commit b241ac6

Please sign in to comment.