Skip to content

Commit

Permalink
Use new upcast conversion API for table.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Jul 6, 2020
1 parent e53eefe commit b8ba0aa
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions packages/ckeditor5-table/src/converters/upcasttable.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ export default function upcastTable() {

const table = conversionApi.writer.createElement( 'table', attributes );

// Insert element on allowed position.
const splitResult = conversionApi.splitToAllowedParent( table, data.modelCursor );

// When there is no split result it means that we can't insert element to model tree, so let's skip it.
if ( !splitResult ) {
if ( !conversionApi.safeInsert( table, data.modelCursor ) ) {
return;
}

conversionApi.writer.insert( table, splitResult.position );
conversionApi.consumable.consume( viewTable, { name: true } );

// Upcast table rows in proper order (heading rows first).
Expand All @@ -63,29 +58,7 @@ export default function upcastTable() {
createEmptyTableCell( conversionApi.writer, conversionApi.writer.createPositionAt( row, 'end' ) );
}

// Set conversion result range.
data.modelRange = conversionApi.writer.createRange(
// Range should start before inserted element
conversionApi.writer.createPositionBefore( table ),
// Should end after but we need to take into consideration that children could split our
// element, so we need to move range after parent of the last converted child.
// before: <allowed>[]</allowed>
// after: <allowed>[<converted><child></child></converted><child></child><converted>]</converted></allowed>
conversionApi.writer.createPositionAfter( table )
);

// Now we need to check where the modelCursor should be.
// If we had to split parent to insert our element then we want to continue conversion inside split parent.
//
// before: <allowed><notAllowed>[]</notAllowed></allowed>
// after: <allowed><notAllowed></notAllowed><converted></converted><notAllowed>[]</notAllowed></allowed>
if ( splitResult.cursorParent ) {
data.modelCursor = conversionApi.writer.createPositionAt( splitResult.cursorParent, 0 );

// Otherwise just continue after inserted element.
} else {
data.modelCursor = data.modelRange.end;
}
conversionApi.updateConversionResult( table, data );
} );
};
}
Expand Down

0 comments on commit b8ba0aa

Please sign in to comment.