Procházet zdrojové kódy

Improve docs & check in table cell refresh post-fixer.

Maciej Gołaszewski před 6 roky
rodič
revize
0832c59674

+ 8 - 6
packages/ckeditor5-table/src/converters/table-cell-refresh-post-fixer.js

@@ -49,12 +49,14 @@ function tableCellRefreshPostFixer( model ) {
 
 // Check if the model table cell requires refreshing to be re-rendered to a proper state in the view.
 //
-// This methods detects changes that will require:
-// - <span> to <p> rename in the view,
-// - adding a missing <paragraph>,
-// - or wrapping a text node in <paragraph>
+// This methods detects changes that will require renaming <span> to <p> (or vice versa) in the view,
 //
-// thus requiring refreshing the table cell view.
+// This method is simple heuristic that check only single change and will give false positive result when many changes will result
+// in a state that does not require renaming in the view.
+//
+// For instance: The <span> to <p> should be renamed when adding an attribute to a <paragraph>.
+// But adding one attribute and removing another will result in false positive: the check for added attribute will see one attribute
+// on a paragraph and will falsy qualify such change as adding attribute to a paragraph without any attribute.
 //
 // @param {module:engine/model/element~Element} tableCell Table cell to check.
 // @param {String} type Type of change.
@@ -87,5 +89,5 @@ function checkRefresh( tableCell, type ) {
 	// For other changes (insert/remove) the <span> to <p> change can occur when:
 	// - sibling is added to a single paragraph (childCount == 2)
 	// - sibling is removed and single paragraph is left (childCount == 1)
-	return tableCell.childCount < 3;
+	return tableCell.childCount <= ( type == 'insert' ? 2 : 1 );
 }