Răsfoiți Sursa

Internal: Minor code simplification.

Marek Lewandowski 5 ani în urmă
părinte
comite
516f7097d1

+ 5 - 4
packages/ckeditor5-table/src/commands/removecolumncommand.js

@@ -34,13 +34,14 @@ export default class RemoveColumnCommand extends Command {
 
 		if ( firstCell ) {
 			const table = firstCell.parent.parent;
-			const tableUtils = this.editor.plugins.get( 'TableUtils' );
-			const tableColumnCount = table && tableUtils.getColumns( table );
+			const tableColumnCount = this.editor.plugins.get( 'TableUtils' ).getColumns( table );
 
 			const tableMap = [ ...new TableWalker( table ) ];
-			const columnIndexes = tableMap.filter( entry => selectedCells.includes( entry.cell ) ).map( el => el.column );
+			const columnIndexes = tableMap.filter( entry => selectedCells.includes( entry.cell ) ).map( el => el.column ).sort();
+			const minColumnIndex = columnIndexes[ 0 ];
+			const maxColumnIndex = columnIndexes[ columnIndexes.length - 1 ];
 
-			this.isEnabled = Math.max.apply( null, columnIndexes ) - Math.min.apply( null, columnIndexes ) < ( tableColumnCount - 1 );
+			this.isEnabled = maxColumnIndex - minColumnIndex < ( tableColumnCount - 1 );
 		} else {
 			this.isEnabled = false;
 		}

+ 4 - 3
packages/ckeditor5-table/src/commands/removerowcommand.js

@@ -34,13 +34,14 @@ export default class RemoveRowCommand extends Command {
 
 		if ( firstCell ) {
 			const table = firstCell.parent.parent;
-			const tableUtils = this.editor.plugins.get( 'TableUtils' );
-			const tableRowCount = table && tableUtils.getRows( table );
+			const tableRowCount = this.editor.plugins.get( 'TableUtils' ).getRows( table );
 
 			const tableMap = [ ...new TableWalker( table ) ];
 			const rowIndexes = tableMap.filter( entry => selectedCells.includes( entry.cell ) ).map( el => el.row );
+			const minRowIndex = rowIndexes[ 0 ];
+			const maxRowIndex = rowIndexes[ rowIndexes.length - 1 ];
 
-			this.isEnabled = Math.max.apply( null, rowIndexes ) - Math.min.apply( null, rowIndexes ) < ( tableRowCount - 1 );
+			this.isEnabled = maxRowIndex - minRowIndex < ( tableRowCount - 1 );
 		} else {
 			this.isEnabled = false;
 		}