The VS Code of video editing, built for agents.
TypeScript
Enhance context command and selection handling in editor API
konstantin-paulus0d51ab494bf6
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.tsindex 327a19c0..fc72f6aa 100644--- a/apps/cli/src/index.ts+++ b/apps/cli/src/index.ts@@ -1110,7 +1110,7 @@ program.command("context").alias("ctx").description(- `Print essential context about the open project (project, entity count, scenes, active scene, playhead, workarea in seconds when set, font families); call this first to orient.`,+ `Print essential context about the open project. Call this first to orient: "this" or "here" may refer to the selection (spatial) or workarea (temporal).`,).action(() => context());diff --git a/apps/web/src/context/editor-api/context.ts b/apps/web/src/context/editor-api/context.tsindex 1990441e..18fea80d 100644--- a/apps/web/src/context/editor-api/context.ts+++ b/apps/web/src/context/editor-api/context.ts@@ -2,9 +2,9 @@* License, v. 2.0. If a copy of the MPL was not distributed with this* file, You can obtain one at http://mozilla.org/MPL/2.0/. */-import { getProjectName } from "@/components/engine/db/global-db";import { ChildOf } from "@/components/engine/components";import { getAllEntities, hasComponent, Not, query } from "bitecs";+import { selectedNodeIds } from "./selection";import type { Engine } from "@/components/engine";import type { Accessor } from "solid-js";@@ -14,13 +14,7 @@ export function handleContextGet(engine: Accessor<Engine>) {const { world } = engine();const c = world.components;- const sceneEids = [...query(world, [c.Geometry, c.Scene, Not(ChildOf('*')), Not(c.Deleted)])];- const scenes = sceneEids.map((eid) => ({- id: eid,- name: c.Name[eid] ?? '',- size: { width: c.Size.width[eid] ?? 0, height: c.Size.height[eid] ?? 0 },- }));-+ const scenes = [...query(world, [c.Geometry, c.Scene, Not(ChildOf('*')), Not(c.Deleted)])];const entityCount = getAllEntities(world).filter((eid) => !hasComponent(world, eid, c.Deleted)).length;const activeSceneId = world.selection.scene !== null ? world.selection.scene : null;const currentFrame = activeSceneId !== null ? (c.Computed.localTime[activeSceneId] ?? 0) : 0;@@ -36,17 +30,17 @@ export function handleContextGet(engine: Accessor<Engine>) {const fontFamilies = [...new Set(["Inter", ...world.fonts.map((f) => f.family)])];const projectId = world.projectId;- const projectName = await getProjectName(projectId);+ const selection = selectedNodeIds(world);return {projectId,- projectName,entityCount,scenes,activeSceneId,currentFrame,workarea,fontFamilies,+ selection,};}}diff --git a/apps/web/src/context/editor-api/selection.ts b/apps/web/src/context/editor-api/selection.tsindex f71ab3e1..6f391bf1 100644--- a/apps/web/src/context/editor-api/selection.ts+++ b/apps/web/src/context/editor-api/selection.ts@@ -90,10 +90,13 @@ function toNodeRef(world: EngineWorld, eid: number): NodeRef {};}-function selectedNodes(world: EngineWorld): NodeRef[] {+export function selectedNodeIds(world: EngineWorld): number[] {const c = world.components;- const eids = query(world, [c.Selected, Or(c.Geometry, c.Group, c.AdjustmentLayer), Not(c.Deleted)]);- return [...eids].map((eid) => toNodeRef(world, eid));+ return [...query(world, [c.Selected, Or(c.Geometry, c.Group, c.AdjustmentLayer), Not(c.Deleted)])];+}++function selectedNodes(world: EngineWorld): NodeRef[] {+ return selectedNodeIds(world).map((eid) => toNodeRef(world, eid));}export function handleSelectionList(engine: Accessor<Engine>) {@@ -120,9 +123,7 @@ export function handleSelectionSet(engine: Accessor<Engine>) {export function handleSelectionFocus(engine: Accessor<Engine>) {return async () => {const { world, camera } = engine();- const c = world.components;- const eids = [...query(world, [c.Selected, Or(c.Geometry, c.Group, c.AdjustmentLayer), Not(c.Deleted)])];- camera.focusEntities(eids);+ camera.focusEntities(selectedNodeIds(world));return selectedNodes(world);}}diff --git a/reference/context.md b/reference/context.mdindex 97661784..9758dca1 100644--- a/reference/context.md+++ b/reference/context.md@@ -12,11 +12,13 @@ One JSON object:```ts{- project: { id: string; name: string };+ projectId: string;entityCount: number;- scenes: Array<{ id: number; name: string; size: Size }>;+ scenes: number[]; // ids of the top-level scenesactiveSceneId: number | null; // null if no scene is activecurrentFrame: number; // current timeline playhead position, in frames+ workarea: { start: number; end: number } | null; // seconds, null if the active scene has nonefontFamilies: string[];+ selection: number[]; // ids of the selected nodes, empty if nothing is selected}```