Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Changed: Enabled context.xWasUndone in collaboration through `Opera…
Browse files Browse the repository at this point in the history
…tion#wasUndone`.
  • Loading branch information
scofalik committed Sep 14, 2018
1 parent f02e994 commit 131b2be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
16 changes: 3 additions & 13 deletions src/model/operation/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand All @@ -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
Expand Down
28 changes: 23 additions & 5 deletions tests/model/operation/transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 ) );

Expand Down

0 comments on commit 131b2be

Please sign in to comment.