Context-Based Undo History

When you have tools that can have many instances, like for example a text editor window, you would need a history for each of those windows, not a global undo history because you want to undo the specific steps when that window is in focus only. This is valid for when windows are not visible, text editors etc. unless you want your action in the global undo history of the editor. Example usage:

-- this function name is as an example, the main idea is that you need to call this when your window gets focus
local function myWindowFocus(myWindow)
    -- lets set our history for this window
    -- 'history' member should be initialized at the window creation like: myWindow.history = require("editor/api/history")
    -- set the current editor history object as the one of our window
    editor.setUndoHistory(myWindow.history)
    -- from now on, the undo/redo will operate on that window's history object, not the editor's global one
end

-- you should call this when your window lost focus
local function myWindowLostFocus(myWindow)
    -- will revert to default editor global history object
    editor.setUndoHistory(nil)
end
Last modified: December 7, 2021

Any further questions?

Join our discord
Our documentation is currently incomplete and undergoing active development. If you have any questions or feedback, please visit this forum thread.