8
0
Quellcode durchsuchen

Fixed: RemoveOperation#isPermanent sometimes had no effect during OT.

Szymon Cofalik vor 8 Jahren
Ursprung
Commit
68b006a163

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

@@ -370,9 +370,13 @@ const ot = {
 				return [ b.getReversed() ];
 			}
 
+			// If `b` is a permanent RemoveOperation it is always more important than transformed operation.
+			if ( b instanceof RemoveOperation && b.isPermanent ) {
+				context.isStrong = false;
+			}
 			// If only one of operations is a remove operation, we force remove operation to be the "stronger" one
 			// to provide more expected results.
-			if ( !context.forceWeakRemove || b.isPermanent ) {
+			else if ( !context.forceWeakRemove ) {
 				if ( a instanceof RemoveOperation && !( b instanceof RemoveOperation ) ) {
 					context.isStrong = true;
 				} else if ( !( a instanceof RemoveOperation ) && b instanceof RemoveOperation ) {

+ 19 - 0
packages/ckeditor5-engine/tests/model/operation/transform.js

@@ -2829,6 +2829,25 @@ describe( 'transform', () => {
 				} );
 			} );
 		} );
+
+		describe( 'by RemoveOperation', () => {
+			it( 'should use isPermanent flag even if both operations are remove operations', () => {
+				const op = new RemoveOperation( new Position( root, [ 8 ] ), 2, new Position( doc.graveyard, [ 0 ] ), baseVersion );
+
+				const transformBy = op.clone();
+				transformBy.isPermanent = true;
+
+				// `context.isStrong` will not be considered, because `transformBy` is permanent.
+				const transOp = transform( op, transformBy, { isStrong: true } );
+
+				expect( transOp.length ).to.equal( 1 );
+
+				expectOperation( transOp[ 0 ], {
+					type: NoOperation,
+					baseVersion: baseVersion + 1
+				} );
+			} );
+		} );
 	} );
 
 	describe( 'NoOperation', () => {