I am trying to send the undo/redo from one user to another user via node.js for real-time editing purposes. This way I can make it so changes that are undone/redone by one user are undone/redone by another user. Due to the recursiveness of the objects, I can’t pass the entire transaction to undo/redo, so I loop through the changes and pass those instead. However, I have two problems:
- If user 1 makes changes to two or more nodes (i.e. deletes the nodes) and undoes/redoes the changes, the passed changes to user 2 will only undo/redo one of the changes (i.e. deletions) instead of the two or more.
- If user 1 undoes/redoes a moved node, the moved node is not affected for user 2.
Every other interaction works flawlessly. Essentially, this is the code I have so far when the model is changed:
if (fileDiagram.undoManager.isUndoingRedoing) {
var changes = [];
if (e.oldValue == 'Undo' && fileDiagram.undoManager.transactionToUndo !== null) {
fileDiagram.undoManager.transactionToUndo.changes.each(function(change) { changes.push(change.change); });
socket.emit('change', {origin: 'diagram-undo', transaction: changes});
} else if (e.oldValue == 'Redo' && fileDiagram.undoManager.transactionToRedo !== null) {
fileDiagram.undoManager.transactionToRedo.changes.each(function(change) { changes.push(change.change); });
socket.emit('change', {origin: 'diagram-redo', transaction: changes});
}
Then for user 2, I have the following which basically checks for an undo or redo event and then sets the transaction to undo/redo and then undoes/redoes the transaction:
if (data.origin == 'diagram-undo') {
fileDiagram.undoManager.transactionToUndo = data.transaction;
fileDiagram.commandHandler.undo();
} else if (data.origin == 'diagram-redo') {
fileDiagram.undoManager.transactionToRedo = data.transaction;
fileDiagram.commandHandler.redo();
}
Thanks in advance for any help you can offer to my two list items above.