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

Commit

Permalink
Text is optional and defaults to empty text.
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Mar 3, 2017
1 parent 5690acf commit 8b04412
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/inputcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class InputCommand extends Command {
* on the beginning of the range (which after removal is a collapsed range).
*
* @param {Object} [options] The command options.
* @param {String} options.text Text to be inserted.
* @param {String} [options.text=''] Text to be inserted.
* @param {module:engine/model/range~Range} [options.range] Range in which the text is inserted. Defaults
* to the first range in the current selection.
* @param {module:engine/model/position~Position} [options.resultPosition] Position at which the selection
Expand All @@ -70,23 +70,19 @@ export default class InputCommand extends Command {
*/
_doExecute( options = {} ) {
const doc = this.editor.document;
const text = options.text;
const text = options.text || '';
const textInsertions = text.length;
const range = options.range || doc.selection.getFirstRange();
const resultPosition = options.resultPosition;

let textInsertions = 0;

doc.enqueueChanges( () => {
const isCollapsedRange = range.isCollapsed;

if ( !isCollapsedRange ) {
this._buffer.batch.remove( range );
}

if ( text && text.length ) {
textInsertions = text.length;
this._buffer.batch.weakInsert( range.start, text );
}
this._buffer.batch.weakInsert( range.start, text );

if ( resultPosition ) {
this.editor.data.model.selection.collapse( resultPosition );
Expand Down
2 changes: 1 addition & 1 deletion tests/inputcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,5 @@ describe( 'InputCommand', () => {
expect( destroy.calledOnce ).to.be.true;
expect( command._buffer ).to.be.null;
} );
} )
} );
} );

0 comments on commit 8b04412

Please sign in to comment.