ソースを参照

Remove Position, Range, Selection imports from view/model.

Maciej Gołaszewski 7 年 前
コミット
8539859f7e

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

@@ -7,7 +7,6 @@
  * @module typing/utils/injecttypingmutationshandling
  */
 
-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';
 
@@ -211,7 +210,7 @@ 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 = this.editor.model.createRange( modelPos, modelPos.getShiftedBy( deletions ) );
 		const insertText = newText.substr( firstChangeAt, insertions );
@@ -232,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;
 

+ 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;

+ 6 - 7
packages/ckeditor5-typing/tests/input.js

@@ -17,7 +17,6 @@ import Writer from '@ckeditor/ckeditor5-engine/src/model/writer';
 
 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';
@@ -260,7 +259,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',
@@ -280,7 +279,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' );
@@ -304,7 +303,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',
@@ -325,7 +324,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',
@@ -346,7 +345,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',
@@ -366,7 +365,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 );
 

+ 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 );