Sfoglia il codice sorgente

Changed: Enabled `context.xWasUndone` in collaboration through `Operation#wasUndone`.

Szymon Cofalik 7 anni fa
parent
commit
93dab04cab

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

@@ -508,22 +508,12 @@ class ContextFactory {
 	// @param {module:engine/model/operation/operation~Operation} opB
 	// @returns {module:engine/model/operation/transform~TransformationContext}
 	getContext( opA, opB, aIsStrong ) {
-		if ( !this._useContext ) {
-			return {
-				aIsStrong,
-				aWasUndone: false,
-				bWasUndone: false,
-				abRelation: null,
-				baRelation: null
-			};
-		}
-
 		return {
 			aIsStrong,
 			aWasUndone: this._wasUndone( opA ),
 			bWasUndone: this._wasUndone( opB ),
-			abRelation: this._getRelation( opA, opB ),
-			baRelation: this._getRelation( opB, opA )
+			abRelation: this._useContext ? this._getRelation( opA, opB ) : null,
+			baRelation: this._useContext ? this._getRelation( opB, opA ) : null
 		};
 	}
 
@@ -542,7 +532,7 @@ class ContextFactory {
 		const originalOp = this._originalOperations.get( op );
 
 		// And check with the document if the original operation was undone.
-		return this._history.isUndoneOperation( originalOp );
+		return originalOp.wasUndone || this._history.isUndoneOperation( originalOp );
 	}
 
 	// Returns a relation between `opA` and an operation which is undone by `opB`. This can be `String` value if a relation

+ 23 - 5
packages/ckeditor5-engine/tests/model/operation/transform/utils.js

@@ -255,7 +255,7 @@ export class Client {
 }
 
 function bufferOperations( operations, client ) {
-	bufferedOperations.add( { operations: operations.map( operation => JSON.stringify( operation ) ), client } );
+	bufferedOperations.add( { operations, client } );
 }
 
 export function syncClients() {
@@ -278,13 +278,31 @@ export function syncClients() {
 				continue;
 			}
 
-			const remoteOperationsJson = clientsOperations[ remoteClient.name ];
-
-			if ( !remoteOperationsJson ) {
+			if ( !clientsOperations[ remoteClient.name ] ) {
 				continue;
 			}
 
-			const remoteOperations = remoteOperationsJson.map( op => OperationFactory.fromJSON( JSON.parse( op ), localClient.document ) );
+			// Stringify and rebuild operations to simulate sending operations. Set `wasUndone`.
+			const remoteOperationsJson = clientsOperations[ remoteClient.name ].map( operation => {
+				operation.wasUndone = remoteClient.document.history.isUndoneOperation( operation );
+
+				const json = JSON.stringify( operation );
+
+				delete operation.wasUndone;
+
+				return json;
+			} );
+
+			const remoteOperations = remoteOperationsJson.map( json => {
+				const parsedJson = JSON.parse( json );
+				const operation = OperationFactory.fromJSON( parsedJson, localClient.document );
+
+				if ( parsedJson.wasUndone ) {
+					operation.wasUndone = true;
+				}
+
+				return operation;
+			} );
 
 			const localOperations = Array.from( localClient.document.history.getOperations( localClient.syncedVersion ) );