How to make a undo/redo function
There's 2 common ways of implementing undo/redo: The Memento Pattern , where you capture the whole current state . It's easy to implement, but memory-inefficient since you need to store similar copies of the whole state. The Command Pattern , where you capture commands/actions that affect the state (the current action and it's inverse action).
https://stackoverflow.com/questions/54416318/how-to-make-a-undo-redo-function