summaryrefslogtreecommitdiff
path: root/apps/web/src/hooks/actions/use-editor-actions.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-04-15 15:45:50 +0200
committerMaze Winther <mazewinther@gmail.com>2026-04-15 15:45:50 +0200
commitc46d28891fee62ca2d3132da876af6411a41d9da (patch)
treef856f71d04c69628f26b904088d675dd298a5080 /apps/web/src/hooks/actions/use-editor-actions.ts
parent66e4367bc4727f1d0bcf8f869529c7518812277e (diff)
downloadopencut-c46d28891fee62ca2d3132da876af6411a41d9da.tar.gz
feat: text / custom masks, fix preview pan, refactor selection
Diffstat (limited to 'apps/web/src/hooks/actions/use-editor-actions.ts')
-rw-r--r--apps/web/src/hooks/actions/use-editor-actions.ts59
1 files changed, 44 insertions, 15 deletions
diff --git a/apps/web/src/hooks/actions/use-editor-actions.ts b/apps/web/src/hooks/actions/use-editor-actions.ts
index 1c4735bb..873fd33a 100644
--- a/apps/web/src/hooks/actions/use-editor-actions.ts
+++ b/apps/web/src/hooks/actions/use-editor-actions.ts
@@ -21,19 +21,27 @@ export function useEditorActions() {
const editor = useEditor();
const { selectedElements, setElementSelection } = useElementSelection();
const { selectedKeyframes, clearKeyframeSelection } = useKeyframeSelection();
+ const selectedMaskPointSelection = useEditor((e) =>
+ e.selection.getSelectedMaskPointSelection(),
+ );
const toggleSnapping = useTimelineStore((s) => s.toggleSnapping);
const rippleEditingEnabled = useTimelineStore((s) => s.rippleEditingEnabled);
const toggleRippleEditing = useTimelineStore((s) => s.toggleRippleEditing);
const hasTimelineSelectionRef = useRef(false);
const clearTimelineSelectionRef = useRef(() => {});
+ const clearTimelineActiveSelectionRef = useRef(() => {});
const timelineScopeRef = useRef<ScopeEntry | null>(null);
const hasTimelineSelection =
- selectedElements.length > 0 || selectedKeyframes.length > 0;
+ selectedElements.length > 0 ||
+ selectedKeyframes.length > 0 ||
+ selectedMaskPointSelection !== null;
hasTimelineSelectionRef.current = hasTimelineSelection;
clearTimelineSelectionRef.current = () => {
- setElementSelection({ elements: [] });
- clearKeyframeSelection();
+ editor.selection.clearSelection();
+ };
+ clearTimelineActiveSelectionRef.current = () => {
+ editor.selection.clearMostSpecificSelection();
};
if (!timelineScopeRef.current) {
@@ -42,6 +50,9 @@ export function useEditorActions() {
clear: () => {
clearTimelineSelectionRef.current();
},
+ clearActive: () => {
+ clearTimelineActiveSelectionRef.current();
+ },
};
}
@@ -257,17 +268,36 @@ export function useEditorActions() {
useActionHandler(
"delete-selected",
() => {
- if (selectedKeyframes.length > 0) {
- editor.timeline.removeKeyframes({ keyframes: selectedKeyframes });
- clearKeyframeSelection();
- return;
+ switch (editor.selection.getActiveSelectionKind()) {
+ case "mask-points":
+ if (!selectedMaskPointSelection) {
+ return;
+ }
+ editor.timeline.deleteCustomMaskPoints({
+ trackId: selectedMaskPointSelection.trackId,
+ elementId: selectedMaskPointSelection.elementId,
+ maskId: selectedMaskPointSelection.maskId,
+ pointIds: selectedMaskPointSelection.pointIds,
+ });
+ return;
+ case "keyframes":
+ if (selectedKeyframes.length === 0) {
+ return;
+ }
+ editor.timeline.removeKeyframes({ keyframes: selectedKeyframes });
+ clearKeyframeSelection();
+ return;
+ case "elements":
+ if (selectedElements.length === 0) {
+ return;
+ }
+ editor.timeline.deleteElements({
+ elements: selectedElements,
+ });
+ return;
+ default:
+ return;
}
- if (selectedElements.length === 0) {
- return;
- }
- editor.timeline.deleteElements({
- elements: selectedElements,
- });
},
undefined,
);
@@ -343,8 +373,7 @@ export function useEditorActions() {
"deselect-all",
() => {
if (!clearActiveScope()) {
- setElementSelection({ elements: [] });
- clearKeyframeSelection();
+ editor.selection.clearMostSpecificSelection();
}
},
undefined,