Răsfoiți Sursa

Fix: The talbe post-fixer should not try to trim table cells that have height of 1.

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

+ 10 - 5
packages/ckeditor5-table/src/converters/table-post-fixer.js

@@ -59,7 +59,7 @@ import TableWalker from './../tablewalker';
  *					<td>XYZ<td>
  *				</tr>
  *			</tbody>
- *		<table>
+ *        </table>
  *
  * In above example the table will be rendered as a table with two rows - one in the header and second one in the body.
  * The table cell with FOO contents will not expand to the body section so its `rowspan` attribute will be changed to `1` (and as
@@ -92,7 +92,7 @@ import TableWalker from './../tablewalker';
  *					<td>XYZ<td>
  *				</tr>
  *			</tbody>
- *		<table>
+ *        </table>
  *
  * **Note** The table post-fixer only ensures proper structure without deeper analysis of the nature of a change. As such it might lead
  * to a structure which was not intended by user changes. In particular it will also fix undo steps (in conjunction with collaboration)
@@ -208,17 +208,22 @@ function findCellsToTrim( table ) {
 	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;
 
-				cellsToTrim.push( { cell, rowspan: newRowspan } );
+				cellsToTrim.push( { cell, rowspan: newRowspan, old: rowspan } );
 			}
 		} else {
-			if ( row + rowspan + headingRows > maxRows ) {
+			if ( row + rowspan + headingRows > maxRows + 1 ) {
 				const newRowspan = maxRows - row - headingRows + 1;
 
-				cellsToTrim.push( { cell, rowspan: newRowspan } );
+				cellsToTrim.push( { cell, rowspan: newRowspan, old: rowspan } );
 			}
 		}
 	}