瀏覽代碼

Removed `.last` from the array returned by `UpcastConversionApi#getSplitParts()`.

Szymon Cofalik 6 年之前
父節點
當前提交
fe6bbcfd95

+ 3 - 6
packages/ckeditor5-engine/src/conversion/upcastdispatcher.js

@@ -349,8 +349,6 @@ export default class UpcastDispatcher {
 			parts = this._splitParts.get( element );
 		}
 
-		parts.last = parts[ parts.length - 1 ];
-
 		return parts;
 	}
 
@@ -569,8 +567,6 @@ function createContextTree( contextDefinition, writer ) {
  * For a reference to any of above paragraphs, the function will return all three paragraphs (the original element included),
  * sorted in the order of their creation (the original element is the first one).
  *
- * The function returns `Array` with elements. Additionally, `.last` property is set on the array for an easy access to the last split part.
- *
  * If given `element` was not split, an array with single element is returned.
  *
  * Example of a usage in a converter code:
@@ -580,6 +576,7 @@ function createContextTree( contextDefinition, writer ) {
  *		conversionApi.convertChildren( myElement, modelCursor );
  *		// ...
  *		const splitParts = conversionApi.getSplitParts( myElement );
+ *		const lastSplitPart = splitParts[ splitParts.length - 1 ];
  *
  *		// Additional processing on all the parts after the children are converted and the original element might be split.
  *		for ( const element of splitParts ) {
@@ -589,11 +586,11 @@ function createContextTree( contextDefinition, writer ) {
  *		// Setting `data.modelRange` basing on split parts:
  *		data.modelRange = conversionApi.writer.createRange(
  *			conversionApi.writer.createPositionBefore( myElement ),
- *			conversionApi.writer.createPositionAfter( splitParts.last )
+ *			conversionApi.writer.createPositionAfter( lastSplitPart )
  *		);
  *
  *		// Setting `data.modelCursor` to continue after the last split element:
- *		data.modelCursor = conversionApi.writer.createPositionAfter( splitParts.last );
+ *		data.modelCursor = conversionApi.writer.createPositionAfter( lastSplitPart );
  *
  * **Tip:** if you are unable to get a reference to the original element (for example because the code is split into multiple converters
  * or even classes) but it was already converted, you might want to check first element in `data.modelRange`. This is a common situation

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

@@ -570,7 +570,7 @@ function prepareToElementConverter( config ) {
 		// Set conversion result range.
 		data.modelRange = new ModelRange(
 			conversionApi.writer.createPositionBefore( modelElement ),
-			conversionApi.writer.createPositionAfter( parts.last )
+			conversionApi.writer.createPositionAfter( parts[ parts.length - 1 ] )
 		);
 
 		// Now we need to check where the `modelCursor` should be.

+ 0 - 2
packages/ckeditor5-engine/tests/conversion/upcastdispatcher.js

@@ -626,7 +626,6 @@ describe( 'UpcastDispatcher', () => {
 					const parts = conversionApi.getSplitParts( modelElement );
 
 					expect( parts ).to.deep.equal( [ modelElement ] );
-					expect( parts.last ).to.equal( modelElement );
 
 					spy();
 
@@ -689,7 +688,6 @@ describe( 'UpcastDispatcher', () => {
 					expect( parts[ 2 ].getChild( 0 ).data ).to.equal( 'xyz' );
 
 					expect( parts[ 0 ] ).to.equal( modelElement );
-					expect( parts.last ).to.equal( parts[ 2 ] );
 
 					spy();