瀏覽代碼

Used the getSelectedTableCells() util in TableSelection. Removed obsolete TableSelection utils by moving the clearTableCellsContents() helper code straight to the plugin.

Aleksander Nowodzinski 5 年之前
父節點
當前提交
1ebc4a09c5
共有 2 個文件被更改,包括 8 次插入53 次删除
  1. 8 4
      packages/ckeditor5-table/src/tableselection.js
  2. 0 49
      packages/ckeditor5-table/src/tableselection/utils.js

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

@@ -12,7 +12,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import TableWalker from './tablewalker';
 import TableUtils from './tableutils';
 import MouseEventsObserver from './tableselection/mouseeventsobserver';
-import { getTableCellsInSelection, clearTableCellsContents } from './tableselection/utils';
+import { getSelectedTableCells } from './utils';
 import { findAncestor } from './commands/utils';
 import cropTable from './tableselection/croptable';
 
@@ -64,7 +64,7 @@ export default class TableSelection extends Plugin {
 	getSelectedTableCells() {
 		const selection = this.editor.model.document.selection;
 
-		const selectedCells = getTableCellsInSelection( selection );
+		const selectedCells = getSelectedTableCells( selection );
 
 		if ( selectedCells.length == 0 ) {
 			return null;
@@ -291,7 +291,7 @@ export default class TableSelection extends Plugin {
 		const [ selection, options ] = args;
 		const model = this.editor.model;
 		const isBackward = !options || options.direction == 'backward';
-		const selectedTableCells = getTableCellsInSelection( selection );
+		const selectedTableCells = getSelectedTableCells( selection );
 
 		if ( !selectedTableCells.length ) {
 			return;
@@ -302,7 +302,11 @@ export default class TableSelection extends Plugin {
 		model.change( writer => {
 			const tableCellToSelect = selectedTableCells[ isBackward ? selectedTableCells.length - 1 : 0 ];
 
-			clearTableCellsContents( model, selectedTableCells );
+			model.change( writer => {
+				for ( const tableCell of selectedTableCells ) {
+					model.deleteContent( writer.createSelection( tableCell, 'in' ) );
+				}
+			} );
 
 			// The insertContent() helper passes the actual DocumentSelection,
 			// while the deleteContent() helper always operates on the abstract clones.

+ 0 - 49
packages/ckeditor5-table/src/tableselection/utils.js

@@ -1,49 +0,0 @@
-/**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
-
-/**
- * @module table/tableselection/utils
- */
-
-/**
- * Clears contents of the passed table cells.
- *
- * This is to be used with table selection
- *
- *		tableSelection.startSelectingFrom( startCell )
- *		tableSelection.setSelectingFrom( endCell )
- *
- *		clearTableCellsContents( editor.model, tableSelection.getSelectedTableCells() );
- *
- * @param {module:engine/model/model~Model} model
- * @param {Iterable.<module:engine/model/element~Element>} tableCells
- */
-export function clearTableCellsContents( model, tableCells ) {
-	model.change( writer => {
-		for ( const tableCell of tableCells ) {
-			model.deleteContent( writer.createSelection( tableCell, 'in' ) );
-		}
-	} );
-}
-
-/**
- * Returns all model cells within the provided model selection.
- *
- * @param {Iterable.<module:engine/model/selection~Selection>} selection
- * @returns {Array.<module:engine/model/element~Element>}
- */
-export function getTableCellsInSelection( selection ) {
-	const cells = [];
-
-	for ( const range of selection.getRanges() ) {
-		const element = range.getContainedElement();
-
-		if ( element && element.is( 'tableCell' ) ) {
-			cells.push( element );
-		}
-	}
-
-	return cells;
-}