Browse Source

Fix: The SetHeaderRowCommand should only analyze rows that are in heading after expanding header.

Maciej Gołaszewski 7 years ago
parent
commit
7cf66c8073

+ 3 - 1
packages/ckeditor5-table/src/commands/setheaderrowcommand.js

@@ -111,8 +111,10 @@ function getOverlappingCells( table, headingRowsToSet, currentHeadingRows ) {
 	const cellsToSplit = [];
 
 	const startAnalysisRow = headingRowsToSet > currentHeadingRows ? currentHeadingRows : 0;
+	// We're analyzing only when headingRowsToSet > 0.
+	const endAnalysisRow = headingRowsToSet - 1;
 
-	const tableWalker = new TableWalker( table, { startRow: startAnalysisRow, endRow: headingRowsToSet } );
+	const tableWalker = new TableWalker( table, { startRow: startAnalysisRow, endRow: endAnalysisRow } );
 
 	for ( const { row, rowspan, cell } of tableWalker ) {
 		if ( rowspan > 1 && row + rowspan > headingRowsToSet ) {

+ 16 - 0
packages/ckeditor5-table/tests/commands/setheaderrowcommand.js

@@ -252,5 +252,21 @@ describe( 'HeaderRowCommand', () => {
 				[ '10', '' ]
 			], { headingRows: 1 } ) );
 		} );
+
+		it( 'should work properly in the first row of a table', () => {
+			setData( model, modelTable( [
+				[ '00', '[]01', '02' ],
+				[ { colspan: 2, rowspan: 2, contents: '10' }, '12' ],
+				[ '22' ]
+			] ) );
+
+			command.execute();
+
+			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
+				[ '00', '[]01', '02' ],
+				[ { colspan: 2, rowspan: 2, contents: '10' }, '12' ],
+				[ '22' ]
+			], { headingRows: 1 } ) );
+		} );
 	} );
 } );