UndoManager.clear not clearing

Hi!

Please, I would like to know if I might be doing something wrong. I’m calling the “diagram.undoManager.clear()” method, but I’m still able do undo some operations after that. Is there any possible reason for this happening?

I need to clear this history because some operations are persisted on my database (like creating a new node, or changing its parent). And my intention is to clear all history after these operations.

Printing the “historyIndex” property on console, even shows the -1 value, meaning that my stack should be empty. However, pressing CTRL Z still have the undo effect.

First, are you calling UndoManager.clear within a transaction? That would not sound like a good idea to me.

I just tried adding this button to a page:
<button onclick="myDiagram.undoManager.clear()">Clear UndoManager</button>

After clicking the button I definitely could not perform any “undo” or “redo”.

Hi walter! Thank you for the support!

Well, I don’t have any transactions opened at this point, however I realized that this behavior might be a side effect of updating my nodeDataArray. After each operation like changing a parent or creating a new node, my application reloads the nodeDataArray from the backend, which will contain a new node or a different parentKey pointer if compared with the previous state.

It happens that I was calling the undoManager.clear after updating my nodeDataArray, like the following:

    this.diagram.startTransaction('update data');
    this.diagram.model.nodeDataArray = this.nodeDataArray;
    this.diagram.commitTransaction('update data');
    this.diagram.undoManager.clear();

Just changing the order of the operations, solved the problem. =D