The VS Code of video editing, built for agents.
TypeScript
Add withEmptiedTracks function to manage keyframe tracks
konstantin-paulus83df6a2a4b9f
diff --git a/apps/web/src/engine/input/shortcuts.ts b/apps/web/src/engine/input/shortcuts.tsindex 32a56cc3..1433275f 100644--- a/apps/web/src/engine/input/shortcuts.ts+++ b/apps/web/src/engine/input/shortcuts.ts@@ -38,6 +38,7 @@ import { applyClipPaths, cancelClipPath } from '../clip-path';import { getDocumentEditor } from '../editor';import { groupSelection, ungroupSelection, unwrapSequenceSelection, wrapSelectionInScene, wrapSelectionInSequence } from '../group';import { getEditHistory } from '../history';+import { withEmptiedTracks } from '../keyframes';import { cancelObjectMask, getObjectTrack, trackObjectMask, undoMaskStroke } from '../object-mask';import { splitAtPlayhead } from '../split';import { Keys, MODIFIER_KEYS, ObjectMaskTool, Pointer } from '../traits';@@ -68,7 +69,7 @@ export function deleteSelection(world: World): void {const selected = [...world.query(Selected)];if (selected.length) {- getDocumentEditor(world).remove(selected);+ getDocumentEditor(world).remove(withEmptiedTracks(selected));}};diff --git a/apps/web/src/engine/keyframes.tsx b/apps/web/src/engine/keyframes.tsxindex 3d0923d1..767c6d32 100644--- a/apps/web/src/engine/keyframes.tsx+++ b/apps/web/src/engine/keyframes.tsx@@ -24,6 +24,7 @@ import {findKeyframeTargetNode,framesToSeconds,getNodeLocalFrame,+ getParentEntity,getPropertyPaths,Paint,PaintType,@@ -144,6 +145,22 @@ export function removeKeyframeTrack(world: World, editor: DocumentEditor, targetif (track) editor.remove(track);}+/**+ * `entities` plus every track they would leave without keyframes, so that+ * removing a track's last keyframes removes the track too.+ */+export function withEmptiedTracks(entities: Entity[]): Entity[] {+ const doomed = new Set(entities);+ for (const entity of entities) {+ if (!entity.has(Keyframe)) continue;+ const track = getParentEntity(entity);+ if (!track?.has(KeyframeTrack) || doomed.has(track)) continue;+ const keyframes = track.get(Cache)?.keyframes ?? [];+ if (keyframes.every((keyframe) => doomed.has(keyframe))) doomed.add(track);+ }+ return [...doomed];+}+/** The props a paint's keyframe holds, by what the paint is. A gradient's stops keep their own. */function paintProperties(paint: Entity): AnimatableProperty[] {switch (paint.get(Paint)?.value ?? PaintType.SOLID) {