Page:
Undo and Redo
Pages
2D Drawing
2D Nodes
Code Edits
Code Services
Containers
Control Input
Engines
Exporting
File System Dock
Getting Started
Home
Input and Actions
Lisp Text
Live Pipelines
Painters
Playing a Game
Popups Menus and Dialogs
Popups and Dialogs
Project Manager
Projects
Render Targets
Resources
Saving Scenes
Scene Tree
Script Screen
Sessions
Signals
Status
The Debugger
The Editor
The REPL
Themes
Tweens
Undo and Redo
User Interface
Widgets
No results
3
Undo and Redo
dxtr edited this page 2026-10-20 10:09:08 +02:00
Table of Contents
Undo and Redo
pyssel/editor keeps a history of the edits made to each scene, which
undo undoes and redo makes again, as Godot's editor keeps one for each
scene. The editor's docks and inspector change scenes only through a
history, and so may your code:
(asdf:load-system :pyssel/editor)
(let* ((level (make-instance 'pyssel/scene-2d:node-2d :name "level"))
(player (pyssel/scene:add-child level (make-instance 'pyssel/scene-2d:node-2d
:name "player")))
(history (pyssel/editor:make-history :name "level.scene")))
(pyssel/editor:rename-node history player "hero")
(pyssel/editor:set-property history player :position (cl-gmath:make-dvec2 :x 40 :y 100))
(list (pyssel/editor:undo history) ; => "Set position"
(pyssel/editor:undo history) ; => "Rename Node"
(pyssel/scene:node-name player) ; => "player"
(pyssel/editor:history-redo-name history))) ; => "Rename Node"
- Edits:
set-property, of a property named by its initarg, as:position, or by its name;add-node,delete-node,move-node, which reorders or reparents, andrename-node;connect-signal, which connects to persist, anddisconnect-signal;add-node-to-groupandremove-node-from-group;set-node-metaandremove-node-meta, for a node's metadata, named by:edit-name, as "Lock Selected". Each makes its change an edit, named for a menu, ashistory-undo-nameandhistory-redo-namegive them: "Undo Rename Node".perform-changemakes any other change an edit, given as a function that makes it and one that undoes it. - Several changes as one:
with-editmakes the changes of its body one edit, undone together, and undoes them should the body fail. Its:merge, a key standing for a gesture made of steps, as a drag in the 2D viewport, has each step join the edit the gesture's first step made, while nothing else changes the history, as Godot'sMERGE_ENDS: one undo takes the drag back whole, and a drag let go where it began leaves no edit. - Merging: settings of one property in a row merge into one edit, so a
slider's drag is one step;
:merge nilkeeps them apart. - Saving:
mark-savednotes that the scene was saved, andhistory-saved-ptells whether it is as it was then, after undoing what was done since or redoing what was undone;mark-unsavednotes that it differs from its file in a way no edit undoes, as when a resource it holds was saved to a file of its own;history-versionmoves on at every change, for a user interface that shows the history, andhistory-structure-versiononly at an edit that does more than set properties, for one that shows the scene's nodes but not their properties, as the Scene dock, which a drag that sets a position each frame then leaves be. - Deleted nodes stay with their edits, to be put back, and are freed
when the history lets the edit go: when undone edits give way to a new
one, when it keeps more than
make-history's:limit, and atclear-history. - Changes made otherwise, as by
(setf node-name)at the REPL, go around the history, which cannot undo them. An undo that finds its scene changed so signals an error and leaves the scene as it was. - Separate histories: each scene has its own, and the project its own
for its settings and the resources opened from the File System dock,
so undoing in one never changes another. Histories made with one
:clock, whichmake-clockmakes, stamp their edits from it:newest-undofinds the one among them whose edit came last, andearliest-redothe one whose undone edit came first, as the editor's Control+Z undoes the newest edit of the scene shown and the project. Text fields keep their own undo, and a focused one takes Control+Z before the editor's shortcut does.
Getting started
The core
Drawing
Scenes
User interface
Games and the editor
- Playing a Game
- Projects
- The Editor
- The File System Dock
- The Script Screen
- The REPL
- The Debugger
- Lisp Text
- Code Services
- Project Manager
- Undo and Redo
- Exporting
The project