8
0
Просмотр исходного кода

Fix: Cannot insert row at index 0 if table has heading rows attribute set.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
b8bd8e075c

+ 6 - 0
packages/ckeditor5-table/src/converters/downcast.js

@@ -173,6 +173,12 @@ export function downcastAttributeChange( options ) {
 
 			const trElement = conversionApi.mapper.toViewElement( tableRow );
 
+			// The TR element might be not converted yet (ie when adding a row to a heading section).
+			// It will be converted by downcastInsertRow() conversion helper.
+			if ( !trElement ) {
+				continue;
+			}
+
 			const desiredParentName = getSectionName( tableWalkerValue );
 
 			if ( desiredParentName !== trElement.parent.name ) {

+ 1 - 0
packages/ckeditor5-table/tests/commands/insertrowcommand.js

@@ -237,6 +237,7 @@ describe( 'InsertRowCommand', () => {
 					[ '10', '11' ]
 				] ) );
 			} );
+
 			it( 'should insert row at the end of a table', () => {
 				setData( model, modelTable( [
 					[ '00', '01' ],

+ 25 - 0
packages/ckeditor5-table/tests/converters/downcast.js

@@ -977,6 +977,31 @@ describe( 'downcast converters', () => {
 			] ) );
 		} );
 
+		it( 'should work with adding table rows at the beginning of a table', () => {
+			setModelData( model, modelTable( [
+				[ '00', '01' ],
+				[ '10', '11' ]
+			], { headingRows: 1 } ) );
+
+			const table = root.getChild( 0 );
+
+			model.change( writer => {
+				writer.setAttribute( 'headingRows', 2, table );
+
+				const tableRow = writer.createElement( 'tableRow' );
+
+				writer.insert( tableRow, table, 0 );
+				writer.insertElement( 'tableCell', tableRow, 'end' );
+				writer.insertElement( 'tableCell', tableRow, 'end' );
+			} );
+
+			expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formattedViewTable( [
+				[ '', '' ],
+				[ '00', '01' ],
+				[ '10', '11' ]
+			], { headingRows: 2 } ) );
+		} );
+
 		describe( 'asWidget', () => {
 			beforeEach( () => {
 				return VirtualTestEditor.create()