diff --git a/src/inputcommand.js b/src/inputcommand.js index 892581e..a4b6815 100644 --- a/src/inputcommand.js +++ b/src/inputcommand.js @@ -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 @@ -70,12 +70,11 @@ 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; @@ -83,10 +82,7 @@ export default class InputCommand extends Command { 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 ); diff --git a/tests/inputcommand.js b/tests/inputcommand.js index db23867..86ba6d6 100644 --- a/tests/inputcommand.js +++ b/tests/inputcommand.js @@ -189,5 +189,5 @@ describe( 'InputCommand', () => { expect( destroy.calledOnce ).to.be.true; expect( command._buffer ).to.be.null; } ); - } ) + } ); } );