Undomanager to skip default delete method


I want the undomanager to skip the default delete method( transaction that is called when link/node is selected and delete key is pressed). This way if a link/node is deleted , it stays deleted.

http://gojs.net/latest/samples/flowchart.html - in this example


Well, I can provide two answers. Please consider both carefully.

First, you can do what you ask for by overriding CommandHandler.deleteSelection to temporarily set Diagram.skipsUndoManager to true, call the base method, and then set it back to its original value.

Second, change your design by not having that feature. The reason I believe it is problematic for users is that it can cause unexpected behavior. Imagine for example that the user first deletes a link that connects with Node X. This is undoable and redoable, and everything is fine.

But what happens (after deleting that link) that the user deletes Node X and that deletion is not recorded in the UndoManager? An undo would restore the deleted link – but there’s no longer any Node X! The diagram will be in an inconsistent state, and users will be confused.

I suppose one solution to the problem would be for you to clear the UndoManager history after deleting Node X, so no undos would be possible then. You can do that by myDiagram.undoManager.clear(). I haven’t tried this, but you would need to be careful about calling it during a transaction – if you did that might cause some problems by itself.