8
0
Pārlūkot izejas kodu

Internal: Enable column removing for multi-cell selection.

Marek Lewandowski 5 gadi atpakaļ
vecāks
revīzija
900d4dcd44

+ 22 - 6
packages/ckeditor5-table/src/commands/removecolumncommand.js

@@ -28,13 +28,10 @@ export default class RemoveColumnCommand extends Command {
 	 * @inheritDoc
 	 */
 	refresh() {
-		const editor = this.editor;
-		const selection = editor.model.document.selection;
-		const tableUtils = editor.plugins.get( 'TableUtils' );
+		const tableUtils = this.editor.plugins.get( 'TableUtils' );
+		const firstCell = this._getReferenceCells().next().value;
 
-		const tableCell = findAncestor( 'tableCell', selection.getFirstPosition() );
-
-		this.isEnabled = !!tableCell && tableUtils.getColumns( tableCell.parent.parent ) > 1;
+		this.isEnabled = !!firstCell && tableUtils.getColumns( firstCell.parent.parent ) > 1;
 	}
 
 	/**
@@ -80,6 +77,25 @@ export default class RemoveColumnCommand extends Command {
 			writer.setSelection( writer.createPositionAt( cellToFocus, 0 ) );
 		} );
 	}
+
+	/**
+	 * Returns cells that are selected and are a reference to removing rows.
+	 *
+	 * @private
+	 * @returns {Iterable.<module:engine/model/element~Element>} Generates `tableCell` elements.
+	 */
+	* _getReferenceCells() {
+		const plugins = this.editor.plugins;
+		if ( plugins.has( 'TableSelection' ) && plugins.get( 'TableSelection' ).hasMultiCellSelection ) {
+			for ( const cell of plugins.get( 'TableSelection' ).getSelectedTableCells() ) {
+				yield cell;
+			}
+		} else {
+			const selection = this.editor.model.document.selection;
+
+			yield findAncestor( 'tableCell', selection.getFirstPosition() );
+		}
+	}
 }
 
 // Returns a proper table cell to focus after removing a column. It should be a next sibling to selection visually stay in place but: