浏览代码

Fix: Splitting table cell vertically in heading section should update table's headingRows attribute.

Maciej Gołaszewski 7 年之前
父节点
当前提交
0537447b6a
共有 2 个文件被更改,包括 28 次插入5 次删除
  1. 6 0
      packages/ckeditor5-table/src/tableutils.js
  2. 22 5
      packages/ckeditor5-table/tests/tableutils.js

+ 6 - 0
packages/ckeditor5-table/src/tableutils.js

@@ -337,6 +337,12 @@ export default class TableUtils extends Plugin {
 				}
 
 				createEmptyRows( writer, table, rowIndex + 1, remaingingRowspan, 1, attributes );
+
+				const headingRows = parseInt( table.getAttribute( 'headingRows' ) || 0 );
+
+				if ( headingRows > rowIndex ) {
+					updateNumericAttribute( 'headingRows', headingRows + 1, table, writer );
+				}
 			}
 		} );
 	}

+ 22 - 5
packages/ckeditor5-table/tests/tableutils.js

@@ -447,7 +447,7 @@ describe( 'TableUtils', () => {
 			] ) );
 		} );
 
-		it( 'should unsplit table cell if split is equal to colspan', () => {
+		it( 'should split table cell if split is equal to colspan', () => {
 			setData( model, modelTable( [
 				[ '00', '01', '02' ],
 				[ '10', '11', '12' ],
@@ -465,7 +465,7 @@ describe( 'TableUtils', () => {
 			] ) );
 		} );
 
-		it( 'should properly unsplit table cell if split is uneven', () => {
+		it( 'should properly split table cell if split is uneven', () => {
 			setData( model, modelTable( [
 				[ '00', '01', '02' ],
 				[ { colspan: 3, contents: '10[]' } ]
@@ -565,7 +565,7 @@ describe( 'TableUtils', () => {
 			] ) );
 		} );
 
-		it( 'should unsplit rowspanned cell', () => {
+		it( 'should split rowspanned cell', () => {
 			setData( model, modelTable( [
 				[ '00', { rowspan: 2, contents: '01[]' } ],
 				[ '10' ],
@@ -629,7 +629,7 @@ describe( 'TableUtils', () => {
 			] ) );
 		} );
 
-		it( 'should unsplit rowspanned cell and updated other cells rowspan when splitting to bigger number of cells', () => {
+		it( 'should split rowspanned cell and updated other cells rowspan when splitting to bigger number of cells', () => {
 			setData( model, modelTable( [
 				[ '00', { rowspan: 2, contents: '01[]' } ],
 				[ '10' ],
@@ -648,7 +648,7 @@ describe( 'TableUtils', () => {
 			] ) );
 		} );
 
-		it( 'should unsplit rowspanned & colspaned cell', () => {
+		it( 'should split rowspanned & colspaned cell', () => {
 			setData( model, modelTable( [
 				[ '00', { colspan: 2, contents: '01[]' } ],
 				[ '10', '11' ]
@@ -665,6 +665,23 @@ describe( 'TableUtils', () => {
 				[ '10', '11' ]
 			] ) );
 		} );
+
+		it( 'should split table cell from a heading section', () => {
+			setData( model, modelTable( [
+				[ '00[]', '01', '02' ],
+				[ '10', '11', '12' ],
+				[ '20', '21', '22' ]
+			], { headingRows: 1 } ) );
+
+			tableUtils.splitCellVertically( root.getNodeByPath( [ 0, 0, 0 ] ) );
+
+			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
+				[ '00[]', { rowspan: 2, contents: '01' }, { rowspan: 2, contents: '02' } ],
+				[ '' ],
+				[ '10', '11', '12' ],
+				[ '20', '21', '22' ]
+			], { headingRows: 2 } ) );
+		} );
 	} );
 
 	describe( 'getColumns()', () => {