Răsfoiți Sursa

Code style: Simplify table post-fixer internals.

Maciej Gołaszewski 7 ani în urmă
părinte
comite
d67f3b09cf

+ 9 - 12
packages/ckeditor5-table/src/converters/table-post-fixer.js

@@ -202,29 +202,26 @@ function fixTableRowsWidths( table, writer ) {
 // @returns {Array.<{{cell, rowspan}}>}
 function findCellsToTrim( table ) {
 	const headingRows = parseInt( table.getAttribute( 'headingRows' ) || 0 );
+	const maxRows = table.childCount;
 
 	const cellsToTrim = [];
 
 	for ( const { row, rowspan, cell } of new TableWalker( table ) ) {
-		const maxRows = table.childCount;
-
 		// Skip cells that do not expand over its row.
 		if ( rowspan < 2 ) {
 			continue;
 		}
 
-		if ( headingRows > row ) {
-			if ( row + rowspan > headingRows ) {
-				const newRowspan = headingRows - row;
+		const isInHeader = row < headingRows;
 
-				cellsToTrim.push( { cell, rowspan: newRowspan, old: rowspan } );
-			}
-		} else {
-			if ( row + rowspan + headingRows > maxRows + 1 ) {
-				const newRowspan = maxRows - row - headingRows + 1;
+		// Row limit is either end of header section or whole table as table body is after the header.
+		const rowLimit = isInHeader ? headingRows : maxRows;
 
-				cellsToTrim.push( { cell, rowspan: newRowspan, old: rowspan } );
-			}
+		// If table cell expands over its limit reduce it height to proper value.
+		if ( row + rowspan > rowLimit ) {
+			const newRowspan = rowLimit - row;
+
+			cellsToTrim.push( { cell, rowspan: newRowspan } );
 		}
 	}
 

+ 1 - 3
packages/ckeditor5-table/tests/converters/table-post-fixer.js

@@ -12,7 +12,7 @@ import TableEditing from '../../src/tableediting';
 import { formatTable, formattedModelTable, modelTable } from './../_utils/utils';
 import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
 
-describe( 'Table Post Fixer', () => {
+describe( 'Table post-fixer', () => {
 	let editor, model, root;
 
 	beforeEach( () => {
@@ -22,9 +22,7 @@ describe( 'Table Post Fixer', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-
 				model = editor.model;
-
 				root = model.document.getRoot();
 			} );
 	} );