Skip to content

Commit

Permalink
Use new upcast conversion API in list upcast.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Jul 20, 2020
1 parent 7458aee commit aa6f0ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
12 changes: 7 additions & 5 deletions packages/ckeditor5-engine/src/conversion/upcastdispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,13 @@ export default class UpcastDispatcher {

const writer = this.conversionApi.writer;

// Set conversion result range.
data.modelRange = writer.createRange(
writer.createPositionBefore( modelElement ),
writer.createPositionAfter( parts[ parts.length - 1 ] )
);
if ( !data.modelRange ) {
// Set conversion result range.
data.modelRange = writer.createRange(
writer.createPositionBefore( modelElement ),
writer.createPositionAfter( parts[ parts.length - 1 ] )
);
}

const savedCursorParent = this._cursorParents.get( modelElement );

Expand Down
18 changes: 2 additions & 16 deletions packages/ckeditor5-list/src/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,30 +378,16 @@ export function viewModelConverter( evt, data, conversionApi ) {
const type = data.viewItem.parent && data.viewItem.parent.name == 'ol' ? 'numbered' : 'bulleted';
writer.setAttribute( 'listType', type, listItem );

// Try to find allowed parent for list item.
const splitResult = conversionApi.splitToAllowedParent( listItem, data.modelCursor );

// When there is no allowed parent it means that list item cannot be converted at current model position
// and in any of position ancestors.
if ( !splitResult ) {
if ( !conversionApi.safeInsert( listItem, data.modelCursor ) ) {
return;
}

writer.insert( listItem, splitResult.position );

const nextPosition = viewToModelListItemChildrenConverter( listItem, data.viewItem.getChildren(), conversionApi );

// Result range starts before the first item and ends after the last.
data.modelRange = writer.createRange( data.modelCursor, nextPosition );

// When `data.modelCursor` parent had to be split to insert list item...
if ( splitResult.cursorParent ) {
// Continue conversion in the split element.
data.modelCursor = writer.createPositionAt( splitResult.cursorParent, 0 );
} else {
// Otherwise continue conversion after the last list item.
data.modelCursor = data.modelRange.end;
}
conversionApi.updateConversionResult( listItem, data );
}
}

Expand Down

0 comments on commit aa6f0ba

Please sign in to comment.