Determine type of update in the panel update method

I’m running some possibly processor intensive events on update() and I want to run those events only if there is a change to the artboard. Right now, if I simply change the selection the update method is called.

Use Case
If the user moved an rectangle then I want to know that the document has changed. If the user simply selected a different rectangle then the document has not changed and I want to avoid running any specific operations.

async update(type) {
  if (type=="selection") updateUI();
  else if (type=="move"|| type=="delete" || type=="valueChange") {
     await exportDocument();
     updateUI();
  }
}

Thanks for submitting this as a feature request. Currently, update function does not tell you what exact change has happened. While you can figure out what changed in your code mostly, we do understand it would be much easier if we provide the types. We will discuss this internally in the next feature request discussion session.

1 Like

I’m running into a case where I’d really need to support undo or redo OR show the history of events. Because I’m writing to pluginData there’s things that can easily break when the user uses undo or redo.

I might be able to minimize the issue if I can get and display the history events.

For example, I’d like to produce a history panel because right now if the user undos a few times they might revert from important changes.

Basically, I want to do this:

History panel:

Create rectangle
Resize rectangle
Change border
Group
Property change description in my plugin ← important
Property change description in my plugin ← important
Move group
Move group
Move group
Move group
Move group
Move group
Add rectangle
Change border

If the user undoes a bunch of times, in the example, let’s say he is undoing his design work, he might accidentally undo the plugin work as I have done many times.

I can see two feature requests.

  • The full history API
  • A smaller one that simply provides and array of history descriptions and their index so I can provide a basic history panel using the update method and then warn users if they are undoing the plugin changes they just made.

Even, more basic, an option to display notifications of what is being undone or redone when you use undo or redo.

I understand that it might not be possible in live editing mode. In a full API it could be a property and generate an error if called. In a basic API getting the changes shouldn’t affect anything. In fact it could have an additional property with the user name, “Bob resized rectangle”.