浏览代码

Move adding empty paragraph to a table cell on remove to table cell paragraph post-fixer.

Maciej Gołaszewski 6 年之前
父节点
当前提交
cf8065205f

+ 28 - 19
packages/ckeditor5-table/src/converters/table-cell-paragraph-post-fixer.js

@@ -42,25 +42,20 @@ function tableCellContentsPostFixer( writer, model ) {
 	let wasFixed = false;
 
 	for ( const entry of changes ) {
-		// Analyze table cells on insertion.
-		if ( entry.type == 'insert' ) {
-			if ( entry.name == 'table' ) {
-				wasFixed = fixTable( entry.position.nodeAfter, writer ) || wasFixed;
-			}
-
-			if ( entry.name == 'tableRow' ) {
-				wasFixed = fixTableRow( entry.position.nodeAfter, writer ) || wasFixed;
-			}
-
-			if ( entry.name == 'tableCell' ) {
-				wasFixed = fixTableCellContent( entry.position.nodeAfter, writer ) || wasFixed;
-			}
-
-			// Check table cell children for directly placed text nodes.
-			// Temporary check. See https://github.com/ckeditor/ckeditor5/issues/1464.
-			if ( entry.name == '$text' && entry.position.parent.is( 'tableCell' ) ) {
-				wasFixed = fixTableCellContent( entry.position.parent, writer ) || wasFixed;
-			}
+		if ( entry.type == 'insert' && entry.name == 'table' ) {
+			wasFixed = fixTable( entry.position.nodeAfter, writer ) || wasFixed;
+		}
+
+		if ( entry.type == 'insert' && entry.name == 'tableRow' ) {
+			wasFixed = fixTableRow( entry.position.nodeAfter, writer ) || wasFixed;
+		}
+
+		if ( entry.type == 'insert' && entry.name == 'tableCell' ) {
+			wasFixed = fixTableCellContent( entry.position.nodeAfter, writer ) || wasFixed;
+		}
+
+		if ( checkTableCellChange( entry ) ) {
+			wasFixed = fixTableCellContent( entry.position.parent, writer ) || wasFixed;
 		}
 	}
 
@@ -121,3 +116,17 @@ function fixTableCellContent( tableCell, writer ) {
 	// Return true when there were text nodes to fix.
 	return !!textNodes.length;
 }
+
+// Check if differ change should fix table cell. This happens on:
+// - removing content from table cell (ie tableCell can be left empty).
+// - adding text node directly into a table cell.
+//
+// @param {Object} differ change entry
+// @returns {Boolean}
+function checkTableCellChange( entry ) {
+	if ( !entry.position || !entry.position.parent.is( 'tableCell' ) ) {
+		return false;
+	}
+
+	return entry.type == 'insert' && entry.name == '$text' || entry.type == 'remove';
+}

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

@@ -61,11 +61,6 @@ function tableCellRefreshPostFixer( model ) {
 // @param {module:engine/model/element~Element} tableCell Table cell to check.
 // @param {String} type Type of change.
 function checkRefresh( tableCell, type ) {
-	// If all children of a table cell were removed - refresh it.
-	if ( !tableCell.childCount ) {
-		return true;
-	}
-
 	const hasInnerParagraph = Array.from( tableCell.getChildren() ).some( child => child.is( 'paragraph' ) );
 
 	// If there is no paragraph in table cell then the view doesn't require refreshing.