Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit a3ea18d

Browse files
authored
Merge pull request #93 from ckeditor/t/92
Fix: Downcast converter for table attributes should work with not converted child elements. Closes #92.
2 parents bce6766 + cccc774 commit a3ea18d

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/converters/downcast.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ export function downcastRemoveRow() {
307307
}, { priority: 'higher' } );
308308
}
309309

310-
// Renames a table cell in the view to a given element name.
310+
// Renames an existing table cell in the view to a given element name.
311+
//
312+
// **Note** This method will not do anything if a view table cell was not yet converted.
311313
//
312314
// @param {module:engine/model/element~Element} tableCell
313315
// @param {String} desiredCellElementName
@@ -316,6 +318,11 @@ export function downcastRemoveRow() {
316318
function renameViewTableCell( tableCell, desiredCellElementName, conversionApi, asWidget ) {
317319
const viewCell = conversionApi.mapper.toViewElement( tableCell );
318320

321+
// View cell might be not yet converted - skip it as it will be properly created by cell converter later on.
322+
if ( !viewCell ) {
323+
return;
324+
}
325+
319326
let renamedCell;
320327

321328
if ( asWidget ) {
@@ -486,6 +493,8 @@ function removeTableSectionIfEmpty( sectionName, tableElement, conversionApi ) {
486493

487494
// Moves view table rows associated with passed model rows to the provided table section element.
488495
//
496+
// **Note** This method will skip not converted table rows.
497+
//
489498
// @param {Array.<module:engine/model/element~Element>} rowsToMove
490499
// @param {module:engine/view/element~Element} viewTableSection
491500
// @param {Object} conversionApi
@@ -494,7 +503,10 @@ function moveViewRowsToTableSection( rowsToMove, viewTableSection, conversionApi
494503
for ( const tableRow of rowsToMove ) {
495504
const viewTableRow = conversionApi.mapper.toViewElement( tableRow );
496505

497-
conversionApi.writer.move( ViewRange.createOn( viewTableRow ), ViewPosition.createAt( viewTableSection, offset ) );
506+
// View table row might be not yet converted - skip it as it will be properly created by cell converter later on.
507+
if ( viewTableRow ) {
508+
conversionApi.writer.move( ViewRange.createOn( viewTableRow ), ViewPosition.createAt( viewTableSection, offset ) );
509+
}
498510
}
499511
}
500512

tests/converters/downcast.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,33 @@ describe( 'downcast converters', () => {
10531053
], { headingRows: 2 } ) );
10541054
} );
10551055

1056+
it( 'should work with adding a table row and expanding heading', () => {
1057+
setModelData( model, modelTable( [
1058+
[ '00', '01' ],
1059+
[ '10', '11' ],
1060+
[ '20', '21' ]
1061+
], { headingRows: 1 } ) );
1062+
1063+
const table = root.getChild( 0 );
1064+
1065+
model.change( writer => {
1066+
writer.setAttribute( 'headingRows', 2, table );
1067+
1068+
const tableRow = writer.createElement( 'tableRow' );
1069+
1070+
writer.insert( tableRow, table, 1 );
1071+
writer.insertElement( 'tableCell', tableRow, 'end' );
1072+
writer.insertElement( 'tableCell', tableRow, 'end' );
1073+
} );
1074+
1075+
expect( formatTable( getViewData( viewDocument, { withoutSelection: true } ) ) ).to.equal( formattedViewTable( [
1076+
[ '00', '01' ],
1077+
[ '', '' ],
1078+
[ '10', '11' ],
1079+
[ '20', '21' ]
1080+
], { headingRows: 2 } ) );
1081+
} );
1082+
10561083
describe( 'asWidget', () => {
10571084
beforeEach( () => {
10581085
return VirtualTestEditor.create()

0 commit comments

Comments
 (0)