Przeglądaj źródła

Other: Make table-post-fixer analyze a table only once.

Maciej Gołaszewski 7 lat temu
rodzic
commit
96d3aea36a

+ 8 - 2
packages/ckeditor5-table/src/converters/table-post-fixer.js

@@ -113,6 +113,9 @@ function tablePostFixer( writer, model ) {
 
 	let wasFixed = false;
 
+	// Do not analyze the same table more then once - may happen for multiple changes in the same table.
+	const analyzedTables = new Set();
+
 	for ( const entry of changes ) {
 		let table;
 
@@ -131,11 +134,14 @@ function tablePostFixer( writer, model ) {
 			table = getParentTable( entry.range.start );
 		}
 
-		if ( table ) {
+		if ( table && !analyzedTables.has( table ) ) {
 			// Step 1: correct rowspans of table cells if necessary.
-			wasFixed = fixTableCellsRowspan( table, writer ) || wasFixed; // Should be true if any of present tables was fixed.
+			// The wasFixed flag should be true if any of tables in batch was fixed - might be more then one.
+			wasFixed = fixTableCellsRowspan( table, writer ) || wasFixed;
 			// Step 2: fix table rows widths.
 			wasFixed = fixTableRowsWidths( table, writer ) || wasFixed;
+
+			analyzedTables.add( table );
 		}
 	}
 

+ 14 - 4
packages/ckeditor5-table/tests/converters/table-post-fixer.js

@@ -133,11 +133,15 @@ describe( 'Table post-fixer', () => {
 				[ '21', '22' ]
 			] );
 			const tableB = modelTable( [
-				[ 'aa' ],
+				[ 'aa', 'ab' ],
 				[ 'ba', 'bb' ]
 			] );
+			const tableC = modelTable( [
+				[ 'xx' ],
+				[ 'yy', 'yy' ]
+			] );
 
-			const parsed = parse( tableA + tableB, model.schema );
+			const parsed = parse( tableA + tableB + tableC, model.schema );
 
 			model.change( writer => {
 				writer.remove( Range.createIn( root ) );
@@ -149,11 +153,17 @@ describe( 'Table post-fixer', () => {
 				[ '21', '22' ]
 			] );
 			const expectedTableB = formattedModelTable( [
-				[ 'aa', '' ],
+				[ 'aa', 'ab' ],
 				[ 'ba', 'bb' ]
 			] );
+			const expectedTableC = formattedModelTable( [
+				[ 'xx', '' ],
+				[ 'yy', 'yy' ]
+			] );
+
+			const expectedTables = expectedTableA + expectedTableB + expectedTableC;
 
-			expect( formatTable( getModelData( model, { withoutSelection: true } ) ) ).to.equal( expectedTableA + expectedTableB );
+			expect( formatTable( getModelData( model, { withoutSelection: true } ) ) ).to.equal( expectedTables );
 		} );
 
 		it( 'should not crash on table remove', () => {