Ver código fonte

Fix: SplitOperation properties were wrong if the split was in graveyard.

Szymon Cofalik 7 anos atrás
pai
commit
26a2c6d0da

+ 2 - 3
packages/ckeditor5-engine/src/model/differ.js

@@ -182,14 +182,13 @@ export default class Differ {
 			}
 			case 'split': {
 				const splitElement = operation.position.parent;
-				const howManyMoved = splitElement.maxOffset - operation.position.offset;
 
 				if ( !this._isInInsertedElement( splitElement ) ) {
-					this._markRemove( splitElement, operation.position.offset, howManyMoved );
+					this._markRemove( splitElement, operation.position.offset, operation.howMany );
 				}
 
 				if ( !this._isInInsertedElement( splitElement.parent ) ) {
-					this._markInsert( splitElement.parent, splitElement.startOffset + 1, 1 );
+					this._markInsert( splitElement.parent, operation.insertionPosition.offset, 1 );
 				}
 
 				break;

+ 14 - 2
packages/ckeditor5-engine/src/model/operation/splitoperation.js

@@ -87,7 +87,13 @@ export default class SplitOperation extends Operation {
 		const path = this.position.path.slice( 0, -1 );
 		path[ path.length - 1 ]++;
 
-		return new Position( this.position.root, path );
+		let pos = new Position( this.position.root, path );
+
+		if ( this.graveyardPosition && this.graveyardPosition.root == pos.root ) {
+			pos = pos._getTransformedByDeletion( this.graveyardPosition, 1 );
+		}
+
+		return pos;
 	}
 
 	/**
@@ -103,7 +109,13 @@ export default class SplitOperation extends Operation {
 		path[ path.length - 1 ]++;
 		path.push( 0 );
 
-		return new Position( this.position.root, path );
+		let pos = new Position( this.position.root, path );
+
+		if ( this.graveyardPosition && this.graveyardPosition.root == pos.root ) {
+			pos = pos._getTransformedByDeletion( this.graveyardPosition, 1 );
+		}
+
+		return pos;
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-engine/src/model/operation/transform.js

@@ -2205,7 +2205,7 @@ setTransformation( SplitOperation, WrapOperation, ( a, b ) => {
 	// was transformed by `UnwrapOperation` and it was left in the unwrapped node. Now the unwrapped node will be re-used
 	// and we need to fix `howMany` property in the `SplitOperation`.
 	//
-	if ( b.graveyardPosition && a.insertionPosition.isEqual( b.graveyardPosition.getShiftedBy( 1 ) ) ) {
+	if ( b.graveyardPosition && compareArrays( b.graveyardPosition.path, a.position.getParentPath() ) == 'same' ) {
 		a.position = a.position._getCombined( b.graveyardPosition, b.position );
 		a.howMany = a.howMany + b.howMany;