What are actions?
Actions represent user-triggered operations like play/pause, split elements, or undo. They bridge the gap between UI interactions and underlying editor operations.The single source of truth for all actions is
apps/web/src/lib/actions/definitions.ts.Action definition
apps/web/src/lib/actions/definitions.ts
Available actions
Here’s a subset of the actions defined in OpenCut:- Playback
- Editing
- History
apps/web/src/lib/actions/definitions.ts
Action invocation
UseinvokeAction() to trigger actions from UI components:
apps/web/src/lib/actions/registry.ts
Actions vs direct editor calls
Understand when to use each approach:- Use actions
- Use direct calls
For user-triggered operations:Benefits:
- Automatic keyboard shortcut handling
- Consistent UX feedback (toasts, validation)
- Centralized action definitions
- Easy to add shortcuts later
Adding a new action
Follow these steps to add a new action:1. Define the action
Add it toACTIONS in apps/web/src/lib/actions/definitions.ts:
apps/web/src/lib/actions/definitions.ts
2. Add the handler
Implement the handler inapps/web/src/hooks/use-editor-actions.ts:
apps/web/src/hooks/use-editor-actions.ts
3. Invoke from UI
Now you can trigger it from any component:Action registry implementation
The action system uses a simple registry pattern:apps/web/src/lib/actions/registry.ts
Keyboard shortcuts
Keyboard shortcuts are automatically mapped from action definitions:apps/web/src/lib/actions/definitions.ts
- Automatic keyboard shortcut handling
- User-customizable shortcuts (future feature)
- Single source of truth for shortcuts
Action categories
Actions are organized by category for better UI organization:- playback - Play, pause, seek operations
- navigation - Timeline navigation and jumping
- editing - Splitting, deleting, copying elements
- selection - Selecting and manipulating selected items
- history - Undo/redo operations
- timeline - Timeline-level operations like bookmarks
- controls - UI control operations
Best practices
Use actions for UI
Always use
invokeAction() for user-triggered operations from UI components.Direct calls for internal
Use direct
editor.* calls in commands, tests, and internal helper functions.Clear descriptions
Write clear, concise action descriptions that appear in UI and docs.
Logical shortcuts
Choose keyboard shortcuts that are intuitive and follow common conventions.
Related concepts
- EditorCore - Understanding the singleton architecture
- Commands - Actions often trigger commands internally
- Timeline - Many actions operate on timeline data