History Class

/api/history.lua

This class has an instance that is available in editor as: editor.history, used as example: editor.history:addAction….

undo(steps)
Parameters:steps – how many steps to undo, default is 1 if not specified

Undo a number of steps from the history stack

redo(steps)
Parameters:steps – how many steps to redo, default is 1 if not specified

Redo a number of steps from the history stack

beginTransaction(name)
Parameters:name – the name of the undo transaction (as a group of actions)

This will start a history transaction of adding multiple actions as a group

cancelTransaction()

Cancels a started transaction. Used when adding actions in a transaction, and some add action failed or data is not valid

endTransaction()

Ends a transaction successfuly and EXECUTES ALL REDO functions from all the added actions in this transaction.

addAction(name, data, undoFunc, redoFunc)
Parameters:
  • name – the name of the action, in the example format “MyCreateWhatever” do not add Action at the end of the string
  • data – the data used by both undo and redo functions, where you keep new and old information about the action done
  • undoFunc – the undo function, which has the format: local function myCreateWhateverUndo(actionData)
  • redoFunc – the redo function, which has the format: local function myCreateWhateverRedo(actionData)

This adds the action on the undo stack AND EXECUTES THE REDO function with the given data table as argument. When this function is called inside a beginTransaction/endTransaction, it will not execute the redo function until endTransaction, when all the redo functions of all the added actions inside that transaction are called at once.

clear()

Clears the history, no functions are called, everything lost.

saveToFile(filename)
Parameters:filename – JSON filename to save into

NOT IMPLEMENTED. Save the history to a JSON file.

loadFromFile(filename)
Parameters:filename – JSON filename to load from

NOT IMPLEMENTED. Load the history from a JSON file.