浏览代码

Changed InputCommand#execute so it supports multi-range selections.

Aleksander Nowodzinski 5 年之前
父节点
当前提交
4218abfd89
共有 1 个文件被更改,包括 3 次插入8 次删除
  1. 3 8
      packages/ckeditor5-typing/src/inputcommand.js

+ 3 - 8
packages/ckeditor5-typing/src/inputcommand.js

@@ -83,25 +83,20 @@ export default class InputCommand extends Command {
 		const doc = model.document;
 		const text = options.text || '';
 		const textInsertions = text.length;
-		const range = options.range || doc.selection.getFirstRange();
+		const selection = options.range ? model.createSelection( options.range ) : doc.selection;
 		const resultRange = options.resultRange;
 
 		model.enqueueChange( this._buffer.batch, writer => {
-			const isCollapsedRange = range.isCollapsed;
-
 			this._buffer.lock();
 
-			model.deleteContent( model.createSelection( range ) );
+			model.deleteContent( selection );
 
 			if ( text ) {
-				model.insertContent( writer.createText( text, doc.selection.getAttributes() ), range.start );
+				model.insertContent( writer.createText( text, doc.selection.getAttributes() ), selection );
 			}
 
 			if ( resultRange ) {
 				writer.setSelection( resultRange );
-			} else if ( isCollapsedRange ) {
-				// If range was collapsed just shift the selection by the number of inserted characters.
-				writer.setSelection( range.start.getShiftedBy( textInsertions ) );
 			}
 
 			this._buffer.unlock();