Override default copy, paste, undo and redo behaviour

I have some additional data added on the Node without using the transaction manager.
This is the temporary data which i dont want gojs to remember. i mean when user is doing undo or redo or copy/paste gojs should not use such temporary data.

so lets say on the node i have added 1 property called as Roles. If user does undo and does redo again, then it should add the node without Roles property.

How can i achieve this ?

You say that you do not want the UndoManager to know about the “Roles” property. So it seems odd to expect the model to know not to copy that property when copying a node data object.

But if that is what you want, you can supply a function that does what you want as the Model | GoJS API

I have implemented this function, it works fine for the copy/paste functionalities.
However the issue for undo and redo is not working as expected. When i am doing undo or redo, copyNodeDataFunction is not called.
I want to remove properties on undo redo operation as well.

Hmm, that seems even more unusual to me. I think you are going to have to implement a “FinishedUndo” and “FinishedRedo” Transaction-type ChangedEvent listener:
https://gojs.net/latest/intro/changedEvents.html#Transactions

We have setup the events FinishedUndo and Finished Redo.
We observed a weird behaviour in the Undo functionality.

We have node, which doesnt have certain property when its added to canvas. After that we added 2-3 properties on that Node without Transaction.

After that we added another node and added 2-3 properties without Transaction.

Now when user is hitting Undo button, it removes the Node which was added to canvas (Since its a part of transaction), but also it removes all the custom properties which were added to previously added Node.

When i am performing an Undo, shouldn’t it revert only what was part of transaction ?

By “without transaction”, what do you mean?

I think it should mean that you:

  • temporarily set skipsUndoManager to true on the Model or the Diagram
  • start the transaction
  • make the property settings
  • commit the transaction
  • set skipsUndoManager back to false

A more concise way of doing that is by calling commit. For example:

  myDiagram.model.commit(function(m) {
      ... set some data properties ...
    }, null);