8
0
Просмотр исходного кода

Review writerSetSelection() API calls with single position.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
0788f8f6ec

+ 4 - 13
packages/ckeditor5-typing/tests/input.js

@@ -57,9 +57,7 @@ describe( 'Input feature', () => {
 				editor.setData( '<p>foobar</p>' );
 
 				model.change( writer => {
-					writer.setSelection(
-						writer.createRange( writer.createPositionAt( modelRoot.getChild( 0 ), 3 ) )
-					);
+					writer.setSelection( modelRoot.getChild( 0 ), 3 );
 				} );
 			} );
 	} );
@@ -385,9 +383,7 @@ describe( 'Input feature', () => {
 
 		it( 'should replace last &nbsp; with space', () => {
 			model.change( writer => {
-				writer.setSelection(
-					writer.createRange( writer.createPositionAt( modelRoot.getChild( 0 ), 6 ) )
-				);
+				writer.setSelection( modelRoot.getChild( 0 ), 6 );
 			} );
 
 			viewDocument.fire( 'mutations', [
@@ -428,9 +424,7 @@ describe( 'Input feature', () => {
 
 		it( 'should replace all &nbsp; with spaces', () => {
 			model.change( writer => {
-				writer.setSelection(
-					writer.createRange( writer.createPositionAt( modelRoot.getChild( 0 ), 6 ) )
-				);
+				writer.setSelection( modelRoot.getChild( 0 ), 6 );
 			} );
 
 			viewDocument.fire( 'mutations', [
@@ -539,10 +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( writer.createRange(
-					writer.createPositionAt( modelRoot.getChild( 0 ), 1 ),
-					writer.createPositionAt( 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

+ 3 - 3
packages/ckeditor5-typing/tests/utils/injectandroidbackspacemutationshandling.js

@@ -60,7 +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( writer.createRange( writer.createPositionAt( modelRoot.getChild( 1 ), 0 ) ) );
+			writer.setSelection( modelRoot.getChild( 1 ), 0 );
 		} );
 
 		const modelContent = '<heading1>Heading 1</heading1><paragraph>[]Paragraph</paragraph><heading2>Heading 2</heading2>';
@@ -293,7 +293,7 @@ describe( 'injectAndroidBackspaceMutationsHandling', () => {
 
 		// 4. Simulate user selection change which is identical as Android native change on 'Backspace'.
 		model.change( writer => {
-			writer.setSelection( writer.createRange( writer.createPositionAt( modelRoot.getChild( 2 ), 0 ) ) );
+			writer.setSelection( modelRoot.getChild( 2 ), 0 );
 		} );
 
 		// 5. Simulate 'Backspace' flow on Android.
@@ -313,7 +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( writer.createRange( writer.createPositionAt( modelRoot.getChild( 1 ), 9 ) ) );
+			writer.setSelection( modelRoot.getChild( 1 ), 9 );
 		} );
 
 		const modelContent = '<heading1>Heading 1</heading1><paragraph>Paragraph[]</paragraph><heading2>Heading 2</heading2>';