Sfoglia il codice sorgente

Update model/view selection docs and tests.

Maciej Gołaszewski 7 anni fa
parent
commit
fa1bea6a29

+ 1 - 1
packages/ckeditor5-engine/src/model/utils/insertcontent.js

@@ -44,7 +44,7 @@ export default function insertContent( model, content, selectable, placeOrOffset
 		} else if ( selectable instanceof Selection || selectable instanceof DocumentSelection ) {
 			selection = selectable;
 		} else {
-			selection = new Selection( selectable, placeOrOffset );
+			selection = writer.createSelection( selectable, placeOrOffset );
 		}
 
 		if ( !selection.isCollapsed ) {

+ 2 - 2
packages/ckeditor5-engine/src/view/documentselection.js

@@ -43,7 +43,7 @@ export default class DocumentSelection {
 	 *		const selection = new DocumentSelection( ranges );
 	 *
 	 *		// Creates selection from the other selection.
-	 *		const otherSelection = new Selection();
+	 *		const otherSelection = writer.createSelection();
 	 *		const selection = new DocumentSelection( otherSelection );
 	 *
 	 * 		// Creates selection at the given position.
@@ -298,7 +298,7 @@ export default class DocumentSelection {
 	 *		documentSelection._setTo( range );
 	 *
 	 *		// Sets selection to the other selection.
-	 *		const otherSelection = new Selection();
+	 *		const otherSelection = writer.createSelection();
 	 *		documentSelection._setTo( otherSelection );
 	 *
 	 * 		// Sets collapsed selection at the given position.

+ 1 - 2
packages/ckeditor5-engine/tests/model/schema.js

@@ -15,7 +15,6 @@ import Text from '../../src/model/text';
 import TextProxy from '../../src/model/textproxy';
 import Position from '../../src/model/position';
 import Range from '../../src/model/range';
-import Selection from '../../src/model/selection';
 
 import { getData, setData, stringify, parse } from '../../src/dev-utils/model';
 
@@ -1187,7 +1186,7 @@ describe( 'Schema', () => {
 			setData( model, input );
 
 			const validRanges = schema.getValidRanges( doc.selection.getRanges(), attribute );
-			const sel = new Selection( validRanges );
+			const sel = model.createSelection( validRanges );
 
 			expect( stringify( root, sel ) ).to.equal( output );
 		}

+ 4 - 5
packages/ckeditor5-engine/tests/model/utils/insertcontent.js

@@ -8,7 +8,6 @@ import insertContent from '../../../src/model/utils/insertcontent';
 import DocumentFragment from '../../../src/model/documentfragment';
 import Text from '../../../src/model/text';
 import Element from '../../../src/model/element';
-import Selection from '../../../src/model/selection';
 import Position from '../../../src/model/position';
 
 import { setData, getData, parse } from '../../../src/dev-utils/model';
@@ -38,7 +37,7 @@ describe( 'DataController utils', () => {
 			model.schema.extend( '$text', { allowIn: '$root' } );
 			setData( model, 'a[]bc' );
 
-			const selection = new Selection( new Position( doc.getRoot(), [ 2 ] ) );
+			const selection = model.createSelection( model.createPositionFromPath( doc.getRoot(), [ 2 ] ) );
 
 			model.change( writer => {
 				insertContent( model, writer.createText( 'x' ), selection );
@@ -50,8 +49,8 @@ describe( 'DataController utils', () => {
 			model.schema.extend( '$text', { allowIn: '$root' } );
 			setData( model, 'a[]bc' );
 
-			const selection = new Selection( new Position( doc.getRoot(), [ 2 ] ) );
-			const selectionCopy = new Selection( new Position( doc.getRoot(), [ 2 ] ) );
+			const selection = model.createSelection( model.createPositionFromPath( doc.getRoot(), [ 2 ] ) );
+			const selectionCopy = model.createSelection( model.createPositionFromPath( doc.getRoot(), [ 2 ] ) );
 
 			expect( selection.isEqual( selectionCopy ) ).to.be.true;
 
@@ -61,7 +60,7 @@ describe( 'DataController utils', () => {
 
 			expect( selection.isEqual( selectionCopy ) ).to.be.false;
 
-			const insertionSelection = new Selection( new Position( doc.getRoot(), [ 3 ] ) );
+			const insertionSelection = model.createSelection( model.createPositionFromPath( doc.getRoot(), [ 3 ] ) );
 			expect( selection.isEqual( insertionSelection ) ).to.be.true;
 		} );
 

+ 2 - 3
packages/ckeditor5-engine/tests/model/utils/modifyselection.js

@@ -4,7 +4,6 @@
  */
 
 import Model from '../../../src/model/model';
-import Selection from '../../../src/model/selection';
 import modifySelection from '../../../src/model/utils/modifyselection';
 import { setData, stringify } from '../../../src/dev-utils/model';
 
@@ -381,7 +380,7 @@ describe( 'DataController utils', () => {
 				// Creating new instance of selection instead of operation on module:engine/model/document~Document#selection.
 				// Document's selection will throw errors in some test cases (which are correct cases, but only for
 				// non-document selections).
-				const testSelection = new Selection( doc.selection );
+				const testSelection = model.createSelection( doc.selection );
 				modifySelection( model, testSelection, { unit: 'codePoint', direction: 'backward' } );
 
 				expect( stringify( doc.getRoot(), testSelection ) ).to.equal( '<p>foob[̂]ar</p>' );
@@ -987,7 +986,7 @@ describe( 'DataController utils', () => {
 			// Creating new instance of selection instead of operation on module:engine/model/document~Document#selection.
 			// Document's selection will throw errors in some test cases (which are correct cases, but only for
 			// non-document selections).
-			const testSelection = new Selection( doc.selection );
+			const testSelection = model.createSelection( doc.selection );
 			modifySelection( model, testSelection, options );
 
 			expect( stringify( doc.getRoot(), testSelection ) ).to.equal( output );