Explorar el Código

Remove redundant checks.

Maciej Gołaszewski hace 5 años
padre
commit
e82182044c

+ 7 - 25
packages/ckeditor5-table/src/commands/mergecellscommand.js

@@ -39,7 +39,6 @@ export default class MergeCellsCommand extends Command {
 	 */
 	execute() {
 		const model = this.editor.model;
-
 		const tableUtils = this.editor.plugins.get( TableUtils );
 
 		model.change( writer => {
@@ -149,34 +148,15 @@ function canMergeCells( selection, tableUtils ) {
 		return false;
 	}
 
-	// All cells must be inside the same table.
-	let firstRangeTable;
-
-	for ( const range of selection.getRanges() ) {
-		// Selection ranges must be set on whole <tableCell> element.
-		if ( range.isCollapsed || !range.isFlat || !range.start.nodeAfter.is( 'tableCell' ) ) {
-			return false;
-		}
-
-		const parentTable = findAncestor( 'table', range.start );
-
-		if ( !firstRangeTable ) {
-			firstRangeTable = parentTable;
-		} else if ( firstRangeTable !== parentTable ) {
-			return false;
-		}
-	}
-
 	const selectedTableCells = getSelectionAffectedTableCells( selection );
 
-	if ( !areCellInTheSameTableSection( selectedTableCells, firstRangeTable ) ) {
+	if ( !areCellInTheSameTableSection( selectedTableCells ) ) {
 		return false;
 	}
 
-	// At this point selection contains ranges over table cells in the same table.
-	// The valid selection is a fully occupied rectangle composed of table cells.
-	// Below we calculate area of selected cells and the area of valid selection.
-	// The area of valid selection is defined by top-left and bottom-right cells.
+	// A valid selection is a fully occupied rectangle composed of table cells.
+	// Below we will calculate the area of a selected table cells and the area of valid selection.
+	// The area of a valid selection is defined by top-left and bottom-right cells.
 	const rows = new Set();
 	const columns = new Set();
 
@@ -227,7 +207,9 @@ function getBiggestRectangleArea( rows, columns ) {
 	return ( lastRow - firstRow + 1 ) * ( lastColumn - firstColumn + 1 );
 }
 
-function areCellInTheSameTableSection( tableCells, table ) {
+function areCellInTheSameTableSection( tableCells ) {
+	const table = findAncestor( 'table', tableCells[ 0 ] );
+
 	const rowIndexes = getRowIndexes( tableCells );
 	const headingRows = parseInt( table.getAttribute( 'headingRows' ) || 0 );
 

+ 0 - 27
packages/ckeditor5-table/tests/commands/mergecellscommand.js

@@ -121,33 +121,6 @@ describe( 'MergeCellsCommand', () => {
 			expect( command.isEnabled ).to.be.false;
 		} );
 
-		it( 'should be false if any range is collapsed in selection', () => {
-			setData( model, modelTable( [
-				[ '00', '01', '02' ]
-			] ) );
-
-			selectNodes( [
-				[ 0, 0, 0, 0, 0 ], // The "00" text node
-				[ 0, 0, 1 ]
-			] );
-
-			expect( command.isEnabled ).to.be.false;
-		} );
-
-		it( 'should be false if any ranges are on different tables', () => {
-			setData( model,
-				modelTable( [ [ '00', '01' ] ] ) +
-				modelTable( [ [ 'aa', 'ab' ] ] )
-			);
-
-			selectNodes( [
-				[ 0, 0, 0 ], // first table
-				[ 1, 0, 1 ] // second table
-			] );
-
-			expect( command.isEnabled ).to.be.false;
-		} );
-
 		it( 'should be false if any table cell with colspan attribute extends over selection area', () => {
 			setData( model, modelTable( [
 				[ '00', { colspan: 2, contents: '01' } ],