Explorar el Código

Merge branch t/ckeditor5-engine/1555

Internal: Use built-in factories of range, position and selection classes. Avoid importing things from the engine. See ckeditor/ckeditor5-engine#1555.
Piotrek Koszuliński hace 7 años
padre
commit
6d438015eb

+ 5 - 7
packages/ckeditor5-typing/src/deletecommand.js

@@ -8,12 +8,10 @@
  */
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
-import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
-import Element from '@ckeditor/ckeditor5-engine/src/model/element';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
-import ChangeBuffer from './utils/changebuffer';
 import count from '@ckeditor/ckeditor5-utils/src/count';
 
+import ChangeBuffer from './utils/changebuffer';
+
 /**
  * The delete command. Used by the {@link module:typing/delete~Delete delete feature} to handle the <kbd>Delete</kbd> and
  * <kbd>Backspace</kbd> keys.
@@ -67,7 +65,7 @@ export default class DeleteCommand extends Command {
 		model.enqueueChange( this._buffer.batch, writer => {
 			this._buffer.lock();
 
-			const selection = new Selection( doc.selection );
+			const selection = writer.createSelection( doc.selection );
 
 			// Do not replace the whole selected content if selection was collapsed.
 			// This prevents such situation:
@@ -173,9 +171,9 @@ export default class DeleteCommand extends Command {
 		const doc = model.document;
 		const selection = doc.selection;
 		const limitElement = model.schema.getLimitElement( selection );
-		const paragraph = new Element( 'paragraph' );
+		const paragraph = writer.createElement( 'paragraph' );
 
-		writer.remove( Range.createIn( limitElement ) );
+		writer.remove( writer.createRangeIn( limitElement ) );
 		writer.insert( paragraph, limitElement );
 
 		writer.setSelection( paragraph, 0 );

+ 1 - 3
packages/ckeditor5-typing/src/utils/changebuffer.js

@@ -7,8 +7,6 @@
  * @module typing/utils/changebuffer
  */
 
-import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
-
 /**
  * Change buffer allows to group atomic changes (like characters that have been typed) into
  * {@link module:engine/model/batch~Batch batches}.
@@ -119,7 +117,7 @@ export default class ChangeBuffer {
 	 */
 	get batch() {
 		if ( !this._batch ) {
-			this._batch = new Batch();
+			this._batch = this.model.createBatch();
 		}
 
 		return this._batch;

+ 2 - 3
packages/ckeditor5-typing/src/utils/injectandroidbackspacemutationshandling.js

@@ -7,7 +7,6 @@
  * @module typing/utils/injectandroidbackspacenutationshandling
  */
 
-import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
 import diff from '@ckeditor/ckeditor5-utils/src/diff';
 
 import { containerChildrenMutated } from './utils';
@@ -26,7 +25,7 @@ export default function injectAndroidBackspaceMutationsHandling( editor ) {
 	const selectionChangeToleranceMs = 200;
 
 	let previousSelection = null;
-	let currentSelection = new Selection( model.document.selection );
+	let currentSelection = model.createSelection( model.document.selection );
 	let latestSelectionChangeMs = Date.now();
 
 	model.document.selection.on( 'change', handleSelectionChange );
@@ -38,7 +37,7 @@ export default function injectAndroidBackspaceMutationsHandling( editor ) {
 	//
 	// @param {Object} evt
 	function handleSelectionChange( evt ) {
-		const newSelection = new Selection( evt.source );
+		const newSelection = model.createSelection( evt.source );
 		if ( !currentSelection.isEqual( newSelection ) ) {
 			previousSelection = currentSelection;
 			currentSelection = newSelection;

+ 7 - 11
packages/ckeditor5-typing/src/utils/injecttypingmutationshandling.js

@@ -7,8 +7,6 @@
  * @module typing/utils/injecttypingmutationshandling
  */
 
-import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
-import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position';
 import diff from '@ckeditor/ckeditor5-utils/src/diff';
 import DomConverter from '@ckeditor/ckeditor5-engine/src/view/domconverter';
 
@@ -167,11 +165,9 @@ class MutationHandler {
 		}
 
 		const insertText = newText.substr( firstChangeAt, insertions );
-		const removeRange = ModelRange.createFromParentsAndOffsets(
-			currentModel,
-			firstChangeAt,
-			currentModel,
-			firstChangeAt + deletions
+		const removeRange = this.editor.model.createRange(
+			this.editor.model.createPositionAt( currentModel, firstChangeAt ),
+			this.editor.model.createPositionAt( currentModel, firstChangeAt + deletions )
 		);
 
 		this.editor.execute( 'input', {
@@ -214,9 +210,9 @@ class MutationHandler {
 		}
 
 		// Get the position in view and model where the changes will happen.
-		const viewPos = new ViewPosition( mutation.node, firstChangeAt );
+		const viewPos = this.editing.view.createPositionAt( mutation.node, firstChangeAt );
 		const modelPos = this.editing.mapper.toModelPosition( viewPos );
-		const removeRange = ModelRange.createFromPositionAndShift( modelPos, deletions );
+		const removeRange = this.editor.model.createRange( modelPos, modelPos.getShiftedBy( deletions ) );
 		const insertText = newText.substr( firstChangeAt, insertions );
 
 		this.editor.execute( 'input', {
@@ -235,7 +231,7 @@ class MutationHandler {
 		}
 
 		const change = getSingleTextNodeChange( mutation );
-		const viewPos = new ViewPosition( mutation.node, change.index );
+		const viewPos = this.editing.view.createPositionAt( mutation.node, change.index );
 		const modelPos = this.editing.mapper.toModelPosition( viewPos );
 		const insertedText = change.values[ 0 ].data;
 
@@ -245,7 +241,7 @@ class MutationHandler {
 			// In this case we don't need to do this before `diff` because we diff whole nodes.
 			// Just change &nbsp; in case there are some.
 			text: insertedText.replace( /\u00A0/g, ' ' ),
-			range: new ModelRange( modelPos )
+			range: this.editor.model.createRange( modelPos )
 		} );
 	}
 }

+ 1 - 3
packages/ckeditor5-typing/src/utils/injectunsafekeystrokeshandling.js

@@ -7,8 +7,6 @@
  * @module typing/utils/injectunsafekeystrokeshandling
  */
 
-import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
-
 import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
 
 /**
@@ -29,7 +27,7 @@ export default function injectUnsafeKeystrokesHandling( editor ) {
 	view.document.on( 'compositionstart', handleCompositionStart, { priority: 'lowest' } );
 
 	view.document.on( 'compositionend', () => {
-		latestCompositionSelection = new Selection( model.document.selection );
+		latestCompositionSelection = model.createSelection( model.document.selection );
 	}, { priority: 'lowest' } );
 
 	// Handles the keydown event. We need to guess whether such keystroke is going to result

+ 2 - 3
packages/ckeditor5-typing/src/utils/utils.js

@@ -7,7 +7,6 @@
  * @module typing/utils/utils
  */
 
-import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
 import diff from '@ckeditor/ckeditor5-utils/src/diff';
 import diffToChanges from '@ckeditor/ckeditor5-utils/src/difftochanges';
 
@@ -61,7 +60,7 @@ export function getSingleTextNodeChange( mutation ) {
 	const change = changes[ 0 ];
 
 	// Which is text.
-	if ( !( change.values[ 0 ] instanceof ViewText ) ) {
+	if ( !( !!change.values[ 0 ] && change.values[ 0 ].is( 'text' ) ) ) {
 		return;
 	}
 
@@ -78,7 +77,7 @@ export function getSingleTextNodeChange( mutation ) {
  * @returns {Boolean}
  */
 export function compareChildNodes( oldChild, newChild ) {
-	if ( oldChild instanceof ViewText && newChild instanceof ViewText ) {
+	if ( !!oldChild && oldChild.is( 'text' ) && !!newChild && newChild.is( 'text' ) ) {
 		return oldChild.data === newChild.data;
 	} else {
 		return oldChild === newChild;

+ 80 - 36
packages/ckeditor5-typing/tests/input.js

@@ -14,12 +14,9 @@ import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter';
 import Input from '../src/input';
 
 import Writer from '@ckeditor/ckeditor5-engine/src/model/writer';
-import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
-import ModelSelection from '@ckeditor/ckeditor5-engine/src/model/selection';
 
 import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
 import ViewElement from '@ckeditor/ckeditor5-engine/src/view/element';
-import ViewSelection from '@ckeditor/ckeditor5-engine/src/view/selection';
 
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
@@ -60,9 +57,7 @@ describe( 'Input feature', () => {
 				editor.setData( '<p>foobar</p>' );
 
 				model.change( writer => {
-					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 3, modelRoot.getChild( 0 ), 3 )
-					);
+					writer.setSelection( modelRoot.getChild( 0 ), 3 );
 				} );
 			} );
 	} );
@@ -262,7 +257,7 @@ describe( 'Input feature', () => {
 		it( 'should set model selection appropriately to view selection passed in mutations event', () => {
 			// This test case emulates spellchecker correction.
 
-			const viewSelection = new ViewSelection();
+			const viewSelection = view.createSelection();
 			viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 6 );
 
 			viewDocument.fire( 'mutations',
@@ -282,7 +277,7 @@ describe( 'Input feature', () => {
 		it( 'should use up to one insert and remove operations (spellchecker)', () => {
 			// This test case emulates spellchecker correction.
 
-			const viewSelection = new ViewSelection();
+			const viewSelection = view.createSelection();
 			viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 6 );
 
 			testUtils.sinon.spy( Writer.prototype, 'insert' );
@@ -306,7 +301,7 @@ describe( 'Input feature', () => {
 			// This test case emulates spellchecker correction.
 			editor.setData( '<p>Foo hous a</p>' );
 
-			const viewSelection = new ViewSelection();
+			const viewSelection = view.createSelection();
 			viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 9 );
 
 			viewDocument.fire( 'mutations',
@@ -327,7 +322,7 @@ describe( 'Input feature', () => {
 			// This test case emulates spellchecker correction.
 			editor.setData( '<p>Bar athat foo</p>' );
 
-			const viewSelection = new ViewSelection();
+			const viewSelection = view.createSelection();
 			viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 8 );
 
 			viewDocument.fire( 'mutations',
@@ -348,7 +343,7 @@ describe( 'Input feature', () => {
 			// This test case emulates spellchecker correction.
 			editor.setData( '<p>Foo hous e</p>' );
 
-			const viewSelection = new ViewSelection();
+			const viewSelection = view.createSelection();
 			viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 9 );
 
 			viewDocument.fire( 'mutations',
@@ -368,7 +363,7 @@ describe( 'Input feature', () => {
 		it( 'should place non-collapsed selection after changing single character (composition)', () => {
 			editor.setData( '<p>Foo house</p>' );
 
-			const viewSelection = new ViewSelection();
+			const viewSelection = view.createSelection();
 			viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 8 );
 			viewSelection.setFocus( viewRoot.getChild( 0 ).getChild( 0 ), 9 );
 
@@ -388,9 +383,7 @@ describe( 'Input feature', () => {
 
 		it( 'should replace last &nbsp; with space', () => {
 			model.change( writer => {
-				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
-				);
+				writer.setSelection( modelRoot.getChild( 0 ), 6 );
 			} );
 
 			viewDocument.fire( 'mutations', [
@@ -409,7 +402,10 @@ describe( 'Input feature', () => {
 		it( 'should replace first &nbsp; with space', () => {
 			model.change( writer => {
 				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 0, modelRoot.getChild( 0 ), 0 )
+					writer.createRange(
+						writer.createPositionAt( modelRoot.getChild( 0 ), 0 ),
+						writer.createPositionAt( modelRoot.getChild( 0 ), 0 )
+					)
 				);
 			} );
 
@@ -428,9 +424,7 @@ describe( 'Input feature', () => {
 
 		it( 'should replace all &nbsp; with spaces', () => {
 			model.change( writer => {
-				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
-				);
+				writer.setSelection( modelRoot.getChild( 0 ), 6 );
 			} );
 
 			viewDocument.fire( 'mutations', [
@@ -539,9 +533,7 @@ describe( 'Input feature', () => {
 			editor.setData( '<p><a href="#"><strong>F</strong></a><strong>oo&nbsp;bar</strong></p>' );
 
 			model.change( writer => {
-				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 1, modelRoot.getChild( 0 ), 1 )
-				);
+				writer.setSelection( modelRoot.getChild( 0 ), 1 );
 			} );
 
 			// We need to change the DOM content manually because typing algorithm actually does not check
@@ -584,7 +576,11 @@ describe( 'Input feature', () => {
 		it( 'should remove contents', () => {
 			model.change( writer => {
 				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+					writer.createRange(
+						writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+						writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+					)
+				);
 			} );
 
 			listenter.listenTo( viewDocument, 'keydown', () => {
@@ -618,7 +614,11 @@ describe( 'Input feature', () => {
 		it( 'should do nothing on arrow key', () => {
 			model.change( writer => {
 				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+					writer.createRange(
+						writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+						writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+					)
+				);
 			} );
 
 			viewDocument.fire( 'keydown', { keyCode: getCode( 'arrowdown' ) } );
@@ -629,7 +629,11 @@ describe( 'Input feature', () => {
 		it( 'should do nothing on ctrl combinations', () => {
 			model.change( writer => {
 				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+					writer.createRange(
+						writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+						writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+					)
+				);
 			} );
 
 			viewDocument.fire( 'keydown', { ctrlKey: true, keyCode: getCode( 'c' ) } );
@@ -640,7 +644,11 @@ describe( 'Input feature', () => {
 		it( 'should do nothing on non printable keys', () => {
 			model.change( writer => {
 				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+					writer.createRange(
+						writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+						writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+					)
+				);
 			} );
 
 			viewDocument.fire( 'keydown', { keyCode: 16 } ); // Shift
@@ -664,7 +672,11 @@ describe( 'Input feature', () => {
 		it( 'should do nothing on tab key', () => {
 			model.change( writer => {
 				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+					writer.createRange(
+						writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+						writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+					)
+				);
 			} );
 
 			viewDocument.fire( 'keydown', { keyCode: 9 } ); // Tab
@@ -685,7 +697,11 @@ describe( 'Input feature', () => {
 
 			model.change( writer => {
 				writer.setSelection(
-					ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+					writer.createRange(
+						writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+						writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+					)
+				);
 			} );
 
 			viewDocument.fire( 'keydown', { keyCode: getCode( 'y' ) } );
@@ -744,7 +760,11 @@ describe( 'Input feature', () => {
 			it( 'should remove contents on composition start key if not during composition', () => {
 				model.change( writer => {
 					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+						writer.createRange(
+							writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+							writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+						)
+					);
 				} );
 
 				viewDocument.fire( 'keydown', { keyCode: 229 } );
@@ -755,7 +775,11 @@ describe( 'Input feature', () => {
 			it( 'should not remove contents on composition start key if during composition', () => {
 				model.change( writer => {
 					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
+						writer.createRange(
+							writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+							writer.createPositionAt( modelRoot.getChild( 0 ), 4 )
+						)
+					);
 				} );
 
 				viewDocument.fire( 'compositionstart' );
@@ -769,7 +793,11 @@ describe( 'Input feature', () => {
 
 				model.change( writer => {
 					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 5 ) );
+						writer.createRange(
+							writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+							writer.createPositionAt( modelRoot.getChild( 0 ), 5 )
+						)
+					);
 				} );
 
 				viewDocument.fire( 'compositionstart' );
@@ -784,7 +812,7 @@ describe( 'Input feature', () => {
 				const documentSelection = model.document.selection;
 
 				// Create empty selection.
-				model.document.selection = new ModelSelection();
+				model.document.selection = model.createSelection();
 
 				viewDocument.fire( 'compositionstart' );
 
@@ -800,7 +828,11 @@ describe( 'Input feature', () => {
 
 				model.change( writer => {
 					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 1 ), 2 ) );
+						writer.createRange(
+							writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+							writer.createPositionAt( modelRoot.getChild( 1 ), 2 )
+						)
+					);
 				} );
 
 				viewDocument.fire( 'compositionstart' );
@@ -814,7 +846,11 @@ describe( 'Input feature', () => {
 
 				model.change( writer => {
 					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 1 ), 2 ) );
+						writer.createRange(
+							writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+							writer.createPositionAt( modelRoot.getChild( 1 ), 2 )
+						)
+					);
 				} );
 
 				viewDocument.fire( 'compositionend' );
@@ -829,14 +865,22 @@ describe( 'Input feature', () => {
 
 				model.change( writer => {
 					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 1 ), 2 ) );
+						writer.createRange(
+							writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+							writer.createPositionAt( modelRoot.getChild( 1 ), 2 )
+						)
+					);
 				} );
 
 				viewDocument.fire( 'compositionend' );
 
 				model.change( writer => {
 					writer.setSelection(
-						ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 1 ), 1 ) );
+						writer.createRange(
+							writer.createPositionAt( modelRoot.getChild( 0 ), 2 ),
+							writer.createPositionAt( modelRoot.getChild( 1 ), 1 )
+						)
+					);
 				} );
 
 				viewDocument.fire( 'keydown', { keyCode: 229 } );

+ 5 - 5
packages/ckeditor5-typing/tests/inputcommand-integration.js

@@ -14,10 +14,7 @@ import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
 import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
 import Enter from '@ckeditor/ckeditor5-enter/src/enter';
 
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
-
-import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
 describe( 'Typing – InputCommand integration', () => {
@@ -74,7 +71,10 @@ describe( 'Typing – InputCommand integration', () => {
 
 	function setSelection( pathA, pathB ) {
 		model.change( writer => {
-			writer.setSelection( new Range( new Position( doc.getRoot(), pathA ), new Position( doc.getRoot(), pathB ) ) );
+			writer.setSelection( writer.createRange(
+				writer.createPositionFromPath( doc.getRoot(), pathA ),
+				writer.createPositionFromPath( doc.getRoot(), pathB )
+			) );
 		} );
 	}
 

+ 5 - 4
packages/ckeditor5-typing/tests/inputcommand.js

@@ -7,8 +7,6 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
 import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
 import InputCommand from '../src/inputcommand';
 import ChangeBuffer from '../src/utils/changebuffer';
 import Input from '../src/input';
@@ -181,7 +179,7 @@ describe( 'InputCommand', () => {
 
 			editor.execute( 'input', {
 				text: 'new',
-				resultRange: new Range( new Position( doc.getRoot(), [ 0, 5 ] ) )
+				resultRange: editor.model.createRange( editor.model.createPositionFromPath( doc.getRoot(), [ 0, 5 ] ) )
 			} );
 
 			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>newba[]r</p>' );
@@ -193,7 +191,10 @@ describe( 'InputCommand', () => {
 
 			editor.execute( 'input', {
 				text: 'new',
-				resultRange: new Range( new Position( doc.getRoot(), [ 0, 3 ] ), new Position( doc.getRoot(), [ 0, 6 ] ) )
+				resultRange: editor.model.createRange(
+					editor.model.createPositionFromPath( doc.getRoot(), [ 0, 3 ] ),
+					editor.model.createPositionFromPath( doc.getRoot(), [ 0, 6 ] )
+				)
 			} );
 
 			expect( getData( model, { selection: true } ) ).to.be.equal( '<p>new[bar]</p>' );

+ 5 - 6
packages/ckeditor5-typing/tests/spellchecking.js

@@ -12,10 +12,6 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
 import Undo from '@ckeditor/ckeditor5-undo/src/undo';
 
-import ViewRange from '@ckeditor/ckeditor5-engine/src/view/range';
-
-import ViewSelection from '@ckeditor/ckeditor5-engine/src/view/selection';
-
 import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
 
@@ -183,10 +179,13 @@ describe( 'Typing – spellchecking integration', () => {
 function emulateSpellcheckerMutation( editor, nodeIndex, rangeStart, rangeEnd, oldText, newText ) {
 	const view = editor.editing.view;
 	const viewRoot = view.document.getRoot();
-	const viewSelection = new ViewSelection();
+	const viewSelection = view.createSelection();
 	const node = viewRoot.getChild( nodeIndex ).getChild( 0 );
 
-	viewSelection.setTo( ViewRange.createFromParentsAndOffsets( node, rangeStart, node, rangeEnd ) );
+	viewSelection.setTo( view.createRange(
+		view.createPositionAt( node, rangeStart ),
+		view.createPositionAt( node, rangeEnd )
+	) );
 
 	view.document.fire( 'mutations',
 		[

+ 2 - 3
packages/ckeditor5-typing/tests/tickets/100.js

@@ -16,7 +16,6 @@ import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversio
 import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
 import ViewElement from '@ckeditor/ckeditor5-engine/src/view/element';
 import ViewContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement';
-import ViewSelection from '@ckeditor/ckeditor5-engine/src/view/selection';
 import MutationObserver from '@ckeditor/ckeditor5-engine/src/view/observer/mutationobserver';
 
 import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
@@ -402,7 +401,7 @@ describe( 'Bug ckeditor5-typing#100', () => {
 
 		const paragraph = viewRoot.getChild( 0 );
 		const strong = paragraph.getChild( 0 );
-		const viewSelection = new ViewSelection( paragraph, 0 );
+		const viewSelection = view.createSelection( paragraph, 0 );
 
 		// Simulate mutations and DOM change.
 		domRoot.childNodes[ 0 ].innerHTML = '<b>textx</b>';
@@ -426,7 +425,7 @@ describe( 'Bug ckeditor5-typing#100', () => {
 
 		const paragraph = viewRoot.getChild( 0 );
 		const strong = paragraph.getChild( 0 );
-		const viewSelection = new ViewSelection( paragraph, 0 );
+		const viewSelection = view.createSelection( paragraph, 0 );
 
 		// Simulate mutations and DOM change.
 		domRoot.childNodes[ 0 ].innerHTML = '<strong>Foo bar </strong><b>apple</b>';

+ 1 - 1
packages/ckeditor5-typing/tests/utils/changebuffer.js

@@ -114,7 +114,7 @@ describe( 'ChangeBuffer', () => {
 		} );
 
 		it( 'is not reset when changes are added to batch which existed previously', () => {
-			const externalBatch = new Batch();
+			const externalBatch = model.createBatch();
 
 			model.change( writer => {
 				writer.insertText( 'a', root );

+ 18 - 23
packages/ckeditor5-typing/tests/utils/injectandroidbackspacemutationshandling.js

@@ -12,7 +12,6 @@ import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
 import Input from '../../src/input';
 import Delete from '../../src/delete';
 
-import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
 import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
 import ViewElement from '@ckeditor/ckeditor5-engine/src/view/element';
 
@@ -61,9 +60,7 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 	it( 'should handle block merging', () => {
 		// 1. Set selection to '<h2>Heading 1</h2><p>{}Paragraph</p><h3>Heading 2</h3>'.
 		model.change( writer => {
-			writer.setSelection(
-				ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 1 ), 0, modelRoot.getChild( 1 ), 0 )
-			);
+			writer.setSelection( modelRoot.getChild( 1 ), 0 );
 		} );
 
 		const modelContent = '<heading1>Heading 1</heading1><paragraph>[]Paragraph</paragraph><heading2>Heading 2</heading2>';
@@ -109,9 +106,9 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 	it( 'should handle two entire blocks removal', () => {
 		// 1. Set selection to '<h2>{Heading 1</h2><p>Paragraph}</p><h3>Heading 2</h3>'.
 		model.change( writer => {
-			writer.setSelection(
-				ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 0, modelRoot.getChild( 1 ), 9 )
-			);
+			writer.setSelection( writer.createRange(
+				writer.createPositionAt( modelRoot.getChild( 0 ), 0 ), writer.createPositionAt( modelRoot.getChild( 1 ), 9 )
+			) );
 		} );
 
 		const modelContent = '<heading1>[Heading 1</heading1><paragraph>Paragraph]</paragraph><heading2>Heading 2</heading2>';
@@ -137,7 +134,7 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 
 		// 3. Create selection which simulate Android behaviour where upon pressing `Backspace`
 		// selection is changed to `<h2>Heading 1</h2><p>Paragraph{}</p><h3>Heading 2</h3>`.
-		const newSelection = ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 1 ), 9, modelRoot.getChild( 1 ), 9 );
+		const newSelection = model.createRange( model.createPositionAt( modelRoot.getChild( 1 ), 9 ) );
 
 		// 4. Simulate 'Backspace' flow on Android.
 		simulateBackspace( mutations, newSelection );
@@ -154,9 +151,9 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 	it( 'should handle two partially selected blocks removal', () => {
 		// 1. Set selection to '<h2>Hea{ding 1</h2><p>Paragraph}</p><h3>Heading 2</h3>'.
 		model.change( writer => {
-			writer.setSelection(
-				ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 3, modelRoot.getChild( 1 ), 9 )
-			);
+			writer.setSelection( writer.createRange(
+				writer.createPositionAt( modelRoot.getChild( 0 ), 3 ), writer.createPositionAt( modelRoot.getChild( 1 ), 9 )
+			) );
 		} );
 
 		const modelContent = '<heading1>Hea[ding 1</heading1><paragraph>Paragraph]</paragraph><heading2>Heading 2</heading2>';
@@ -182,7 +179,7 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 
 		// 3. Create selection which simulate Android behaviour where upon pressing `Backspace`
 		// selection is changed to `<h2>Heading 1</h2><p>Paragraph{}</p><h3>Heading 2</h3>`.
-		const newSelection = ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 1 ), 9, modelRoot.getChild( 1 ), 9 );
+		const newSelection = model.createRange( model.createPositionAt( modelRoot.getChild( 1 ), 9 ) );
 
 		// 4. Simulate 'Backspace' flow on Android.
 		simulateBackspace( mutations, newSelection );
@@ -199,9 +196,9 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 
 		// 1. Set selection to '<h2>{Heading 1</h2><p>Paragraph</p><h3>]<i>Heading</i> 2</h3>'.
 		model.change( writer => {
-			writer.setSelection(
-				ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 0, modelRoot.getChild( 2 ), 0 )
-			);
+			writer.setSelection( writer.createRange(
+				writer.createPositionAt( modelRoot.getChild( 0 ), 0 ), writer.createPositionAt( modelRoot.getChild( 2 ), 0 )
+			) );
 		} );
 
 		const modelContent = '<heading1>[Heading 1</heading1><paragraph>Paragraph</paragraph>' +
@@ -233,7 +230,7 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 
 		// 3. Create selection which simulate Android behaviour where upon pressing `Backspace`
 		// selection is changed to `<h2>Heading 1</h2><p>Paragraph</p><h3><em>{}Heading</em> 2</h3>`.
-		const newSelection = ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 2 ), 0, modelRoot.getChild( 2 ), 0 );
+		const newSelection = model.createRange( model.createPositionAt( modelRoot.getChild( 2 ), 0 ) );
 
 		// 4. Simulate 'Backspace' flow on Android.
 		simulateBackspace( mutations, newSelection );
@@ -261,9 +258,9 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 
 		// 2. Set selection to '<h2>{Heading 1</h2><p>Paragraph</p><h3>]<i>Heading</i> 2</h3>'.
 		model.change( writer => {
-			writer.setSelection(
-				ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 0, modelRoot.getChild( 2 ), 0 )
-			);
+			writer.setSelection( writer.createRange(
+				writer.createPositionAt( modelRoot.getChild( 0 ), 0 ), writer.createPositionAt( modelRoot.getChild( 2 ), 0 )
+			) );
 		} );
 
 		const modelContent = '<heading1>[Heading 1</heading1><paragraph>Paragraph</paragraph>' +
@@ -296,7 +293,7 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 
 		// 4. Simulate user selection change which is identical as Android native change on 'Backspace'.
 		model.change( writer => {
-			writer.setSelection( ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 2 ), 0, modelRoot.getChild( 2 ), 0 ) );
+			writer.setSelection( modelRoot.getChild( 2 ), 0 );
 		} );
 
 		// 5. Simulate 'Backspace' flow on Android.
@@ -316,9 +313,7 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 	it( 'should not be triggered for container insertion mutations', () => {
 		// 1. Set selection to '<h2>Heading 1</h2><p>Paragraph{}</p><h3>Heading 2</h3>'.
 		model.change( writer => {
-			writer.setSelection(
-				ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 1 ), 9, modelRoot.getChild( 1 ), 9 )
-			);
+			writer.setSelection( modelRoot.getChild( 1 ), 9 );
 		} );
 
 		const modelContent = '<heading1>Heading 1</heading1><paragraph>Paragraph[]</paragraph><heading2>Heading 2</heading2>';