Explorar o código

Use new upcast conversion API in list upcast.

Maciej Gołaszewski %!s(int64=5) %!d(string=hai) anos
pai
achega
aa6f0baf21

+ 7 - 5
packages/ckeditor5-engine/src/conversion/upcastdispatcher.js

@@ -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 );
 

+ 2 - 16
packages/ckeditor5-list/src/converters.js

@@ -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 );
 	}
 }