Any way to listen to undo from plugin?

Is there any way to listen to an undo action from our plugins? Would love to see something similar to the update callback… This should be pretty simple to implement and I don’t see any security/consistency concerns…
I really need this desperately. Otherwise our plugins cannot properly support undo which is really bad from UX perspective :smiley:

2 Likes

May I ask what’s the use-case here? Or, to put it in another way: Are you “only” asking to get a “read-only” notification about undo or actually gain the option to “interact” with undo?

If you’re asking about read-access (i.e., a simple notification without granting scenegraph editing rights), this should be covered by Support for history commands (as you then could just detect undo by comparing the history on update())…

I need just a notification/callback - so yes basically just read access.
Comparing the entire history on EVERY update is not an option. That would be super expensive. Especially as long es we don’t even have such a thing as a separate “selectionChange” callback. Right now I would have to compare the history on every time the user selects/deselects something. That would be extremely unnecessary and expensive.
In the link you send is no really solution. What exactly do you mean with “it should be covered by that”?

2 Likes

In the feature request, there is a request for a method along the lines of getHistoryArray(). While it, of course, depends on the implementation of such a method, this would probably make it feasible to see, based on the change of the value of this array, like in the pseudocode implementation below:

afterUndo = null // What latest history entry would be after undo

onUpdate {
  if (afterUndo == getHistory()[length - 1]) // History has moved back one entry
    // Undo
  else
    // not undo
  afterUndo = gethistory()[length - 2]
}
1 Like

That might work. You could also pass that information to the update callback.

In that feature request when update was called it would tell you what action initiated the call. You could probably have a second optional parameter that is if the action is undo or redo or first time.

function update(type, history) {
    if (type=="selection") {}
    if (type=="move" && history=="redo") {}
}

Related: