Przeglądaj źródła

Fix: AttributeOperation x InsertOperation OT alogirthm improvements.

Szymon Cofalik 7 lat temu
rodzic
commit
f711f8c0b7

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

@@ -437,7 +437,7 @@ setTransformation( AttributeOperation, InsertOperation, ( a, b ) => {
 	}
 
 	// If insert operation is not expanding the attribute operation range, simply transform the range.
-	a.range = a.range._getTransformedByInsertOperation( b )[ 0 ];
+	a.range = a.range._getTransformedByInsertion( b.position, b.howMany, false )[ 0 ];
 
 	return [ a ];
 } );
@@ -681,7 +681,7 @@ setTransformation( AttributeOperation, UnwrapOperation, ( a, b ) => {
 setTransformation( InsertOperation, AttributeOperation, ( a, b ) => {
 	const result = [ a ];
 
-	if ( a.shouldReceiveAttributes && b.range.containsPosition( a.position ) ) {
+	if ( a.shouldReceiveAttributes && a.position.hasSameParentAs( b.range.start ) && b.range.containsPosition( a.position ) ) {
 		result.push( ..._getComplementaryAttributeOperations( a, b.key, b.newValue ) );
 	}
 

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

@@ -281,6 +281,18 @@ describe( 'transform', () => {
 
 				expectClients( '<paragraph><$text bold="true">Foxxxo</$text></paragraph>' );
 			} );
+
+			it( 'type inside element which attribute changes', () => {
+				john.setData( '[<paragraph></paragraph>]' );
+				kate.setData( '<paragraph>[]</paragraph>' );
+
+				john.setAttribute( 'bold', true );
+				kate.type( 'x' );
+
+				syncClients();
+
+				expectClients( '<paragraph bold="true">x</paragraph>' );
+			} );
 		} );
 
 		describe( 'by move', () => {