浏览代码

Use new upcast conversion API for code block.

Maciej Gołaszewski 5 年之前
父节点
当前提交
4b71659d2b

+ 3 - 37
packages/ckeditor5-code-block/src/converters.js

@@ -193,48 +193,14 @@ export function dataViewToModelCodeBlockInsertion( editingView, languageDefs ) {
 
 		writer.append( fragment, codeBlock );
 
-		// Let's see if the codeBlock can be inserted the current modelCursor.
-		const splitResult = conversionApi.splitToAllowedParent( codeBlock, 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 ) {
+		// Let's try to insert code block.
+		if ( !conversionApi.safeInsert( codeBlock, data.modelCursor ) ) {
 			return;
 		}
 
-		// Insert element on allowed position.
-		writer.insert( codeBlock, splitResult.position );
-
 		consumable.consume( viewItem, { name: true } );
 		consumable.consume( viewChild, { name: true } );
 
-		const parts = conversionApi.getSplitParts( codeBlock );
-
-		// Set conversion result range.
-		data.modelRange = writer.createRange(
-			conversionApi.writer.createPositionBefore( codeBlock ),
-			conversionApi.writer.createPositionAfter( parts[ parts.length - 1 ] )
-		);
-
-		// If we had to split parent to insert our element then we want to continue conversion inside
-		// the split parent.
-		//
-		// before split:
-		//
-		//		<allowed><notAllowed>[]</notAllowed></allowed>
-		//
-		// after split:
-		//
-		//		<allowed>
-		//			<notAllowed></notAllowed>
-		//			<converted></converted>
-		//			<notAllowed>[]</notAllowed>
-		//		</allowed>
-		if ( splitResult.cursorParent ) {
-			data.modelCursor = writer.createPositionAt( splitResult.cursorParent, 0 );
-		} else {
-			// Otherwise just continue after the inserted element.
-			data.modelCursor = data.modelRange.end;
-		}
+		conversionApi.updateConversionResult( codeBlock, data );
 	};
 }

+ 1 - 1
packages/ckeditor5-engine/src/conversion/upcastdispatcher.js

@@ -164,7 +164,7 @@ export default class UpcastDispatcher {
 		this.conversionApi.getSplitParts = this._getSplitParts.bind( this );
 		this.conversionApi.getCursorParent = this._getCursorParent.bind( this );
 		this.conversionApi.safeInsert = this._safeInsert.bind( this );
-		this.conversionApi.updateConversionData = this._updateConversionResult.bind( this );
+		this.conversionApi.updateConversionResult = this._updateConversionResult.bind( this );
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-engine/src/conversion/upcasthelpers.js

@@ -571,7 +571,7 @@ function prepareToElementConverter( config ) {
 
 		conversionApi.consumable.consume( data.viewItem, match );
 		conversionApi.convertChildren( data.viewItem, modelElement );
-		conversionApi.updateConversionData( modelElement, data );
+		conversionApi.updateConversionResult( modelElement, data );
 	};
 }