Support for history commands

Support for history commands including undo(), redo(), markHistoryEvent(“Moved 10 pixels left”), isDirty() and getHistoryArray().

In plugins it’s often the case that your plugin makes a change. Having access to undo() would allow your plugin to make changes and then undo them without exiting the plugin.

Use Case
Bob writes a plugin that modifies the artboard but sometimes his changes are temporary. He adds an line to the artboard, gets the rotation matrix and then uses command.undo() to remove it.

Bob wants the default font information so he temporarily adds a text field to the artboard, gets the font values and then uses command.undo() to remove the text field.

Use Case
Greta is making an History panel for XD. She gets the history commands and fills the undo history list. She has undo and redo buttons that call command.undo() and command.redo().

Use Case
Victor is making an instructional plugin that teaches people how to use XD. His first guide is adding a rectangle to the stage and setting the fill to a linear gradient.

When he adds an ellipse and sets the linear gradient. At each step he calls markHistoryEvent() then uses the undo() command to go back to the first step. He has created a step by step walk through.

Then the user is instructed to exit the plugin and use the undo and redo shortcuts to move forward step by step in the action history.

I think until visual versioning is released it may not considered
any ideas @kerrishotts

Another related feature would be a revert() command.

Whenever a change is made in my plugin but an error occurs, all of those changes are reverted when the plugin dialog closes. So I think this method exists already.

If this API could be exposed then plugin authors could call it manually when the user clicks the cancel button.

@Velara we will be adding undo() soon. what’s the difference between undo and revert? Other requests won’t be implemented in the near future but more use cases would help!

In the Alignment plugin here each time you click an icon the selected items are positioned on the stage. Each change would create an undo history item.

If there was an undo() button in the UI pressing it would go back one step at a time. If you clicked the icons in the Alignment plugin 5 times there would be 5 undo history events.

But if the plugin throws an error then XD will revert all changes to before the plugin dialog was invoked. So if you made 5 alignment changes during the plugin session when you closed your plugin all 5 changes would be reverted (due to that error).

Or if you make multiple changes in the plugin and then exit out of the plugin all of those changes can be undone in one undo history event.

Undo would revert each individual change, revert is undo all session changes. So if the plugin is currently open revert() would revert all the changes back to before the plugin was open.


XD product is working on live editing functionality that will unfortunately make this impossible

@stevekwak This conversation happened 1 year ago but I wonder when do you plan to release undo(). I can not find any documentation about it.

There is a Trello board here where you can see the roadmap for plugin APIs, but unfortunately history commands are not being planned: