Parcourir la source

Internal: Removed second method with very similar semantics. Reused existing one.

Marek Lewandowski il y a 5 ans
Parent
commit
ec82ab544e

+ 3 - 6
packages/ckeditor5-table/src/commands/splitcellcommand.js

@@ -9,7 +9,7 @@
 
 
 import Command from '@ckeditor/ckeditor5-core/src/command';
 import Command from '@ckeditor/ckeditor5-core/src/command';
 import { findAncestor } from './utils';
 import { findAncestor } from './utils';
-import { getSelectedCells } from '../tableselection/utils';
+import { getTableCellsInSelection } from '../tableselection/utils';
 
 
 /**
 /**
  * The split cell command.
  * The split cell command.
@@ -47,12 +47,9 @@ export default class SplitCellCommand extends Command {
 	 * @inheritDoc
 	 * @inheritDoc
 	 */
 	 */
 	refresh() {
 	refresh() {
-		const selectedCellsGenerator = getSelectedCells( this.editor, true );
+		const selectedCells = getTableCellsInSelection( this.editor.model.document.selection, true );
 
 
-		const tableCell = selectedCellsGenerator.next().value;
-		const hasMoreCells = selectedCellsGenerator.next().done == false;
-
-		this.isEnabled = !!tableCell && !hasMoreCells;
+		this.isEnabled = selectedCells.length === 1;
 	}
 	}
 
 
 	/**
 	/**

+ 7 - 28
packages/ckeditor5-table/src/tableselection/utils.js

@@ -34,9 +34,10 @@ export function clearTableCellsContents( model, tableCells ) {
  * Returns all model cells within the provided model selection.
  * Returns all model cells within the provided model selection.
  *
  *
  * @param {Iterable.<module:engine/model/selection~Selection>} selection
  * @param {Iterable.<module:engine/model/selection~Selection>} selection
+ * @param {Boolean} [expandSelection=false] If set to `true` expands the selection to entire cell (if possible).
  * @returns {Array.<module:engine/model/element~Element>}
  * @returns {Array.<module:engine/model/element~Element>}
  */
  */
-export function getTableCellsInSelection( selection ) {
+export function getTableCellsInSelection( selection, expandSelection = false ) {
 	const cells = [];
 	const cells = [];
 
 
 	for ( const range of selection.getRanges() ) {
 	for ( const range of selection.getRanges() ) {
@@ -47,35 +48,13 @@ export function getTableCellsInSelection( selection ) {
 		}
 		}
 	}
 	}
 
 
-	return cells;
-}
-
-/**
- * Yields selected table cells.
- *
- * @private
- * @param {module:core/editor/editor~Editor} editor
- * @param {Boolean} [expandSelection=false] If set to `true` expands the selection to entire cell (if possible).
- * @returns {Iterable.<module:engine/model/element~Element>}
- */
-export function* getSelectedCells( editor, expandSelection = false ) {
-	const plugins = editor.plugins;
-	if ( plugins.has( 'TableSelection' ) ) {
-		const selectedCells = plugins.get( 'TableSelection' ).getSelectedTableCells();
-
-		if ( selectedCells ) {
-			for ( const cell of selectedCells ) {
-				yield cell;
-			}
-
-			return;
-		}
-	}
-
 	if ( expandSelection ) {
 	if ( expandSelection ) {
-		const cellAncestor = findAncestor( 'tableCell', editor.model.document.selection.getFirstPosition() );
+		const cellAncestor = findAncestor( 'tableCell', selection.getFirstPosition() );
+
 		if ( cellAncestor ) {
 		if ( cellAncestor ) {
-			yield cellAncestor;
+			cells.push( cellAncestor );
 		}
 		}
 	}
 	}
+
+	return cells;
 }
 }