Преглед изворни кода

Update table-cell-refresh-post-fixer comments and internal code.

Maciej Gołaszewski пре 5 година
родитељ
комит
270359f979
1 измењених фајлова са 23 додато и 17 уклоњено
  1. 23 17
      packages/ckeditor5-table/src/converters/table-cell-refresh-post-fixer.js

+ 23 - 17
packages/ckeditor5-table/src/converters/table-cell-refresh-post-fixer.js

@@ -50,21 +50,7 @@ function tableCellRefreshPostFixer( model ) {
 	// 2. For each table cell:
 	for ( const [ tableCell, changes ] of changesForCells.entries() ) {
 		// 2a. Count inserts/removes as diff and marks any attribute change.
-		const { childDiff, attribute } = changes.reduce( ( summary, change ) => {
-			if ( change.type === 'remove' ) {
-				summary.childDiff--;
-			}
-
-			if ( change.type === 'insert' ) {
-				summary.childDiff++;
-			}
-
-			if ( change.type === 'attribute' ) {
-				summary.attribute = true;
-			}
-
-			return summary;
-		}, { childDiff: 0, attribute: false } );
+		const { childDiff, attribute } = getChangesSummary( changes );
 
 		// 2b. If we detect that number of children has changed...
 		if ( childDiff !== 0 ) {
@@ -99,9 +85,29 @@ function tableCellRefreshPostFixer( model ) {
 				differ.refreshItem( paragraph );
 			}
 		}
-
-		return false; // TODO tmp
 	}
 
+	// Always return false to prevent the refresh post-fixer from re-running on the same set of changes and going into an infinite loop.
+	// See https://github.com/ckeditor/ckeditor5/issues/1936.
 	return false;
 }
+
+function updateSummaryFromChange( summary, change ) {
+	if ( change.type === 'remove' ) {
+		summary.childDiff--;
+	}
+
+	if ( change.type === 'insert' ) {
+		summary.childDiff++;
+	}
+
+	if ( change.type === 'attribute' ) {
+		summary.attribute = true;
+	}
+
+	return summary;
+}
+
+function getChangesSummary( changes ) {
+	return changes.reduce( updateSummaryFromChange, { childDiff: 0, attribute: false } );
+}