When I move a node, the undoManager.history is as shown in the first screenshot. After completing an undo (calling commandHandler.undo()) the history is as shown in the second screenshot containing no Move transactions, therefore Redo has no move to redo.
In doing some digging, I came across a post experiencing somewhat similar behavior and inserted this provided potential solution in my initDiagram() function:
// skips all events - prevents all events from being added to undoManager history
diagram.model.undoManager.skipsEvent = function(e) {
if (e !== null && e.diagram !== null) return true;
return go.UndoManager.prototype.skipsEvent.call(this, e);
};
// commits a transaction for each move and updates target bindings, undo/redo works properly but affects other bindings
diagram.model.addChangedListener(function(e) {
if (e === null) return;
setTimeout(function() {
diagram.commit(function(d) {
d.updateAllTargetBindings();
}, null);
}, 1);
});
This has gotten me the closest to the desired behavior, undo and redo work properly but it messes up other functionalities related to other bindings. However, I have not been able to successfully specify the individual binding. The binding for the location of the nodes is as follows:
new Binding('location', 'nodeLocation', toPoint).makeTwoWay(fromPoint)
Some questions I have on potential solutions:
- Is there a way to modify the skipsEvent/addChangedListener to ignore the layout events in the undoManager so that, in this use case, only the Move events are recorded?
- Is there a way to modify the updateAllTargetBindings (or use an alternative) to only update the nodeLocation/location binding?
Thanks in advance for any help that can be provided!