Overview
Commands handle undo/redo by saving state before making changes. They live in@/lib/commands/ organized by domain:
timeline/- Timeline operations (split, delete, move elements)media/- Media operations (add/remove assets)scene/- Scene operations (create, delete, bookmarks)project/- Project operations (update settings)
Command base class
All commands extend theCommand base class from @/lib/commands/base-command.
execute()
Performs the operation. Should save the current state before making changes to enable undo.undo()
Reverts the operation by restoring saved state.redo()
Re-applies the operation. Default implementation callsexecute() again. Override if you need custom redo behavior.
Creating a command
Here’s a complete example of a command that deletes elements:Usage
Ctrl+Z / Ctrl+Shift+Z.
BatchCommand
TheBatchCommand class allows executing multiple commands as a single undoable operation.
How it works
- execute(): Executes all commands in order
- undo(): Undoes all commands in reverse order
- redo(): Re-executes all commands in order
Command examples
SplitElementsCommand
Splits timeline elements at a specific time:AddTrackCommand
Adds a new track to the timeline:Best practices
Always save state in execute()
Use immutable updates
Store constructor parameters
Commands need their parameters for potential re-execution:Check state before undo
Related
- Actions - Action system for user operations
- CommandManager - Managing command history and undo/redo