8
0
Pārlūkot izejas kodu

Fixed: Properly handle splitting cells vertically that have colspan.

Maciej Gołaszewski 7 gadi atpakaļ
vecāks
revīzija
7161c6779e

+ 9 - 3
packages/ckeditor5-table/src/tableutils.js

@@ -330,7 +330,13 @@ export default class TableUtils extends Plugin {
 					}
 					}
 				}
 				}
 
 
-				createEmptyRows( writer, table, rowIndex + 1, remaingingRowspan, 1 );
+				const attributes = {};
+
+				if ( colspan > 1 ) {
+					attributes.colspan = colspan;
+				}
+
+				createEmptyRows( writer, table, rowIndex + 1, remaingingRowspan, 1, attributes );
 			}
 			}
 		} );
 		} );
 	}
 	}
@@ -360,14 +366,14 @@ export default class TableUtils extends Plugin {
 // @param {Number} insertAt Row index of row insertion.
 // @param {Number} insertAt Row index of row insertion.
 // @param {Number} rows Number of rows to create.
 // @param {Number} rows Number of rows to create.
 // @param {Number} tableCellToInsert Number of cells to insert in each row.
 // @param {Number} tableCellToInsert Number of cells to insert in each row.
-function createEmptyRows( writer, table, insertAt, rows, tableCellToInsert ) {
+function createEmptyRows( writer, table, insertAt, rows, tableCellToInsert, attributes = {} ) {
 	for ( let i = 0; i < rows; i++ ) {
 	for ( let i = 0; i < rows; i++ ) {
 		const tableRow = writer.createElement( 'tableRow' );
 		const tableRow = writer.createElement( 'tableRow' );
 
 
 		writer.insert( tableRow, table, insertAt );
 		writer.insert( tableRow, table, insertAt );
 
 
 		for ( let columnIndex = 0; columnIndex < tableCellToInsert; columnIndex++ ) {
 		for ( let columnIndex = 0; columnIndex < tableCellToInsert; columnIndex++ ) {
-			const cell = writer.createElement( 'tableCell' );
+			const cell = writer.createElement( 'tableCell', attributes );
 
 
 			writer.insert( cell, tableRow, 'end' );
 			writer.insert( cell, tableRow, 'end' );
 		}
 		}

+ 18 - 0
packages/ckeditor5-table/tests/tableutils.js

@@ -647,6 +647,24 @@ describe( 'TableUtils', () => {
 				[ '20', '21' ]
 				[ '20', '21' ]
 			] ) );
 			] ) );
 		} );
 		} );
+
+		it( 'should unsplit rowspanned & colspaned cell', () => {
+			setData( model, modelTable( [
+				[ '00', { colspan: 2, contents: '01[]' } ],
+				[ '10', '11' ]
+			] ) );
+
+			const tableCell = root.getNodeByPath( [ 0, 0, 1 ] );
+
+			tableUtils.splitCellVertically( tableCell, 3 );
+
+			expect( formatTable( getData( model ) ) ).to.equal( formattedModelTable( [
+				[ { rowspan: 3, contents: '00' }, { colspan: 2, contents: '01[]' } ],
+				[ { colspan: 2, contents: '' } ],
+				[ { colspan: 2, contents: '' } ],
+				[ '10', '11' ]
+			] ) );
+		} );
 	} );
 	} );
 
 
 	describe( 'getColumns()', () => {
 	describe( 'getColumns()', () => {