瀏覽代碼

Added missing wasFixed flag in post-fixer. Added CK_DEBUG_TABLE to table post-fixers.

Kuba Niegowski 5 年之前
父節點
當前提交
fddac60d46

+ 4 - 0
packages/ckeditor5-table/src/converters/table-cell-paragraph-post-fixer.js

@@ -100,6 +100,8 @@ function fixTableRow( tableRow, writer ) {
 function fixTableCellContent( tableCell, writer ) {
 	// Insert paragraph to an empty table cell.
 	if ( tableCell.childCount == 0 ) {
+		// @if CK_DEBUG_TABLE // console.log( 'Post-fixing table: insert paragraph in empty cell.' );
+
 		writer.insertElement( 'paragraph', tableCell );
 
 		return true;
@@ -109,6 +111,8 @@ function fixTableCellContent( tableCell, writer ) {
 	// Temporary solution. See https://github.com/ckeditor/ckeditor5/issues/1464.
 	const textNodes = Array.from( tableCell.getChildren() ).filter( child => child.is( 'text' ) );
 
+	// @if CK_DEBUG_TABLE // textNodes.length && console.log( 'Post-fixing table: wrap cell content with paragraph.' );
+
 	for ( const child of textNodes ) {
 		writer.wrap( writer.createRangeOn( child ), 'paragraph' );
 	}

+ 2 - 0
packages/ckeditor5-table/src/converters/table-cell-refresh-post-fixer.js

@@ -48,6 +48,8 @@ function tableCellRefreshPostFixer( model ) {
 	}
 
 	if ( cellsToRefresh.size ) {
+		// @if CK_DEBUG_TABLE // console.log( `Post-fixing table: refreshing cells (${ cellsToRefresh.size }).` );
+
 		for ( const tableCell of cellsToRefresh.values() ) {
 			differ.refreshItem( tableCell );
 		}

+ 13 - 3
packages/ckeditor5-table/src/converters/table-layout-post-fixer.js

@@ -271,6 +271,8 @@ function fixTableCellsRowspan( table, writer ) {
 	const cellsToTrim = findCellsToTrim( table );
 
 	if ( cellsToTrim.length ) {
+		// @if CK_DEBUG_TABLE // console.log( `Post-fixing table: trimming cells row-spans (${ cellsToTrim.length }).` );
+
 		wasFixed = true;
 
 		for ( const data of cellsToTrim ) {
@@ -300,9 +302,15 @@ function fixTableRowsSizes( table, writer ) {
 	}
 
 	// Remove empty rows.
-	for ( const rowIndex of rowsToRemove.reverse() ) {
-		writer.remove( table.getChild( rowIndex ) );
-		rowsLengths.splice( rowIndex, 1 );
+	if ( rowsToRemove.length ) {
+		// @if CK_DEBUG_TABLE // console.log( `Post-fixing table: remove empty rows (${ rowsToRemove.length }).` );
+
+		wasFixed = true;
+
+		for ( const rowIndex of rowsToRemove.reverse() ) {
+			writer.remove( table.getChild( rowIndex ) );
+			rowsLengths.splice( rowIndex, 1 );
+		}
 	}
 
 	// Verify if all the rows have the same number of columns.
@@ -310,6 +318,8 @@ function fixTableRowsSizes( table, writer ) {
 	const isValid = rowsLengths.every( length => length === tableSize );
 
 	if ( !isValid ) {
+		// @if CK_DEBUG_TABLE // console.log( 'Post-fixing table: adding missing cells.' );
+
 		// Find the maximum number of columns.
 		const maxColumns = rowsLengths.reduce( ( prev, current ) => current > prev ? current : prev, 0 );