Explorar el Código

Update code to the latest engine API.

Maciej Gołaszewski hace 7 años
padre
commit
9f6871ddc3

+ 4 - 6
packages/ckeditor5-table/src/commands/mergecellscommand.js

@@ -8,8 +8,6 @@
  */
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import TableWalker from '../tablewalker';
 import { findAncestor, updateNumericAttribute } from './utils';
 import TableUtils from '../tableutils';
@@ -58,7 +56,7 @@ export default class MergeCellsCommand extends Command {
 			const firstTableCell = selectedTableCells.shift();
 
 			// TODO: this shouldn't be necessary (right now the selection could overlap existing.
-			writer.setSelection( Range.createIn( firstTableCell ) );
+			writer.setSelection( firstTableCell, 'in' );
 
 			const { row, column } = tableUtils.getCellLocation( firstTableCell );
 
@@ -94,7 +92,7 @@ export default class MergeCellsCommand extends Command {
 			updateNumericAttribute( 'colspan', rightMax - column, firstTableCell, writer );
 			updateNumericAttribute( 'rowspan', bottomMax - row, firstTableCell, writer );
 
-			writer.setSelection( Range.createIn( firstTableCell ) );
+			writer.setSelection( firstTableCell, 'in' );
 
 			// Remove empty rows after merging table cells.
 			for ( const row of rowsToCheck ) {
@@ -136,10 +134,10 @@ function removeEmptyRow( removedTableCellRow, writer ) {
 function mergeTableCells( cellToRemove, cellToExpand, writer ) {
 	if ( !isEmpty( cellToRemove ) ) {
 		if ( isEmpty( cellToExpand ) ) {
-			writer.remove( Range.createIn( cellToExpand ) );
+			writer.remove( writer.createRangeIn( cellToExpand ) );
 		}
 
-		writer.move( Range.createIn( cellToRemove ), Position.createAt( cellToExpand, 'end' ) );
+		writer.move( writer.createRangeIn( cellToRemove ), writer.createPositionAt( cellToExpand, 'end' ) );
 	}
 
 	// Remove merged table cell.

+ 1 - 2
packages/ckeditor5-table/src/commands/removecolumncommand.js

@@ -12,7 +12,6 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 import TableWalker from '../tablewalker';
 import TableUtils from '../tableutils';
 import { findAncestor, updateNumericAttribute } from './utils';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 
 /**
  * The remove column command.
@@ -90,7 +89,7 @@ export default class RemoveColumnCommand extends Command {
 				}
 			}
 
-			writer.setSelection( Range.createCollapsedAt( cellToFocus ) );
+			writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
 		} );
 	}
 }

+ 1 - 1
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -104,7 +104,7 @@ export default class RemoveRowCommand extends Command {
 				return isCellToFocusAfterRemoving( row, rowToFocus, rowspan, column, columnToFocus, colspan );
 			} );
 
-			writer.setSelection( Range.createCollapsedAt( cellToFocus ) );
+			writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
 		} );
 	}
 }

+ 4 - 7
packages/ckeditor5-table/src/tableselection.js

@@ -7,13 +7,10 @@
  * @module table/tableselection
  */
 
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
-
 import TableWalker from './tablewalker';
 import { findAncestor } from './commands/utils';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
-import ObservableMixin from '../../ckeditor5-utils/src/observablemixin';
+import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
 
 // TODO: refactor to an Observer
 export default class TableSelection {
@@ -38,7 +35,7 @@ export default class TableSelection {
 
 				editor.model.change( writer => {
 					// Select the contents of table cell.
-					writer.setSelection( Range.createIn( tableCell ) );
+					writer.setSelection( tableCell, 'in' );
 				} );
 			}
 		} );
@@ -186,7 +183,7 @@ export default class TableSelection {
 
 		for ( const tableCell of selected ) {
 			const viewElement = mapper.toViewElement( tableCell );
-			modelRanges.push( Range.createOn( tableCell ) );
+			modelRanges.push( model.createRangeOn( tableCell ) );
 
 			this._highlighted.add( viewElement );
 		}
@@ -228,7 +225,7 @@ function getTableCell( domEventData, editor ) {
 		return;
 	}
 
-	return findAncestor( 'tableCell', Position.createAt( modelElement ) );
+	return findAncestor( 'tableCell', editor.model.createPositionAt( modelElement, 0 ) );
 }
 
 mix( TableSelection, ObservableMixin );

+ 2 - 3
packages/ckeditor5-table/tests/commands/mergecellscommand.js

@@ -9,7 +9,6 @@ import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model
 import MergeCellsCommand from '../../src/commands/mergecellscommand';
 import { defaultConversion, defaultSchema, formatTable, formattedModelTable, modelTable } from '../_utils/utils';
 import TableUtils from '../../src/tableutils';
-import Range from '@ckeditor/ckeditor5-engine/src/model/range';
 
 describe( 'MergeCellsCommand', () => {
 	let editor, model, command, root;
@@ -411,9 +410,9 @@ describe( 'MergeCellsCommand', () => {
 	} );
 
 	function selectNodes( paths ) {
-		const ranges = paths.map( path => Range.createOn( root.getNodeByPath( path ) ) );
-
 		model.change( writer => {
+			const ranges = paths.map( path => writer.createRangeOn( root.getNodeByPath( path ) ) );
+
 			writer.setSelection( ranges );
 		} );
 	}

+ 1 - 1
packages/ckeditor5-table/tests/tableediting.js

@@ -812,7 +812,7 @@ describe( 'TableEditing', () => {
 
 			// The click in the DOM would trigger selection change and it will set the selection:
 			model.change( writer => {
-				writer.setSelection( Range.createCollapsedAt( model.document.getRoot().getChild( 1 ) ) );
+				writer.setSelection( writer.createRange( writer.createPositionAt( model.document.getRoot().getChild( 1 ), 0 ) ) );
 			} );
 
 			expect( formatTable( getViewData( view ) ) ).to.equal( formattedViewTable( [