瀏覽代碼

InputCommand accepts Range instead of Position as a parameter.

Krzysztof Krztoń 8 年之前
父節點
當前提交
8a7ef194ec
共有 2 個文件被更改,包括 7 次插入7 次删除
  1. 3 3
      packages/ckeditor5-typing/src/input.js
  2. 4 4
      packages/ckeditor5-typing/src/inputcommand.js

+ 3 - 3
packages/ckeditor5-typing/src/input.js

@@ -184,10 +184,10 @@ class MutationHandler {
 		}
 
 		// Try setting new model selection according to passed view selection.
-		let modelSelectionPosition = null;
+		let modelSelectionRange = null;
 
 		if ( viewSelection ) {
-			modelSelectionPosition = this.editing.mapper.toModelPosition( viewSelection.anchor );
+			modelSelectionRange = this.editing.mapper.toModelRange( viewSelection.getFirstRange() );
 		}
 
 		// Get the position in view and model where the changes will happen.
@@ -199,7 +199,7 @@ class MutationHandler {
 		this.editor.execute( 'input', {
 			text: insertText,
 			range: removeRange,
-			resultPosition: modelSelectionPosition
+			resultRange: modelSelectionRange
 		} );
 	}
 

+ 4 - 4
packages/ckeditor5-typing/src/inputcommand.js

@@ -64,7 +64,7 @@ export default class InputCommand extends Command {
 	 * @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
+	 * @param {module:engine/model/range~Range} [options.resultRange] Range at which the selection
 	 * should be placed after the insertion. If not specified, the selection will be placed right after
 	 * the inserted text.
 	 */
@@ -73,7 +73,7 @@ export default class InputCommand extends Command {
 		const text = options.text || '';
 		const textInsertions = text.length;
 		const range = options.range || doc.selection.getFirstRange();
-		const resultPosition = options.resultPosition;
+		const resultRange = options.resultRange;
 
 		doc.enqueueChanges( () => {
 			const isCollapsedRange = range.isCollapsed;
@@ -86,8 +86,8 @@ export default class InputCommand extends Command {
 
 			this._buffer.batch.weakInsert( range.start, text );
 
-			if ( resultPosition ) {
-				this.editor.data.model.selection.collapse( resultPosition );
+			if ( resultRange ) {
+				this.editor.data.model.selection.setRanges( [ resultRange ] );
 			} else if ( isCollapsedRange ) {
 				// If range was collapsed just shift the selection by the number of inserted characters.
 				this.editor.data.model.selection.collapse( range.start.getShiftedBy( textInsertions ) );