Reverting the entire edit operation

In some cases, when something goes wrong, the plugin breaks and everything goes back to default, and all the changes that the plugin applied to the content will be reverted. So now how can we have this “reversion” process through the API? To be more clear, suppose we want to have a “Reset to default” button.

There might be something already in the API that I am missing, any advice is appreciated.

Hi @Ali,
Are you talking about reverting changes made in the previous plugin runs (basically “undo cmd+z”)?

Hi, Ali – Good idea. I’m moving this to the API Feature Requests section.

Something like this, maybe (just thinking out loud):

const history = require("scenegraph");
/*...*/
history.undo();

Hi @stevekwak,
Yes, something like “undo”, but not on the previous plugin runs, on the current live changes applied by the plugin, while the dialog is still open. So let’s say that we have changed the size and position of a few elements through some controls, then we decide to “reset the changes”, now we can have a button, for example says “reset to default”, that clicking on it reverts the changes, while we are still using the plugin.

@kerrishotts
Hi Kerri,
That is exactly what I have in mind. It would be very helpful to have this feature when the live changes are too complex to revert.

Can’t the plugin just fail in some way, and have all its changes undone?

It can, but you’d no longer be able to make any other changes to the scenegraph, since you’d have to reject the promise returned to the menu handler. So once you trigger reset, your plugin can’t do anything else.