The VS Code of video editing, built for agents.
TypeScript
Refactor variable handling in inspector and editor
konstantin-paulusa4b785b5cc6c
diff --git a/apps/web/src/components/sidebar-right/inspector/variables.tsx b/apps/web/src/components/sidebar-right/inspector/variables.tsxindex a74cbf1c..f4ec82a2 100644--- a/apps/web/src/components/sidebar-right/inspector/variables.tsx+++ b/apps/web/src/components/sidebar-right/inspector/variables.tsx@@ -95,9 +95,9 @@ function VariableControl(props: { entry: InspectEntry }) {<Match when={entry().type === "font"}><ControlRow label={entry().label}><FontDropdown- family={String(entry().get())}- // Hovering previews on the signal alone; closing puts the- // authored family back (the dropdown hands it back itself).+ family={String(entry().committed())}+ // Hovering previews on the live signal alone; closing puts the+ // committed family back (the dropdown hands it back itself).onPreview={(family) => entry().set(family)}onFamilyChange={(family) => {commit(family);diff --git a/apps/web/src/engine/editor.ts b/apps/web/src/engine/editor.tsindex 163790c2..84fca003 100644--- a/apps/web/src/engine/editor.ts+++ b/apps/web/src/engine/editor.ts@@ -349,9 +349,10 @@ export class DocumentEditor {public editVariable(file: string, name: string, value: InspectValue): void {const entry = findInspectEntry(this.world, file, name);if (!entry) return;- const previous = entry.get();+ // Against the committed value, not the live one+ const previous = entry.committed();+ entry.commit(value);if (previous === value) return;- entry.set(value);this.emit({ kind: 'variable', file, name, value, previous });}diff --git a/packages/reconciler/src/inspect.ts b/packages/reconciler/src/inspect.tsindex 9e6bcaed..88f74c83 100644--- a/packages/reconciler/src/inspect.ts+++ b/packages/reconciler/src/inspect.ts@@ -36,8 +36,17 @@ export interface InspectEntry {options?: string[];/** What the source declared, before anyone touched the signal. */initial: InspectValue;+ /** The live value — what the composition reads, previews included. */get: Accessor<InspectValue>;+ /** Moves the live value alone: a hover preview, taken back on commit. */set: (value: InspectValue) => void;+ /**+ * The last committed value — where the live value returns to when a+ * preview ends, and the `previous` an edit of the variable inverts to.+ */+ committed: Accessor<InspectValue>;+ /** Settles a value: the live signal and the committed one, together. */+ commit: (value: InspectValue) => void;}// Module evaluation is synchronous (see `evaluate`), so one slot is enough:@@ -71,6 +80,7 @@ function prettify(name: string): string {export function __inspect(declaration: InspectDeclaration, initial: InspectValue): Accessor<InspectValue> {const [get, set] = createSignal(initial);+ const [committed, setCommitted] = createSignal(initial);const path = declaration.path ?? [];collecting?.push({@@ -86,6 +96,11 @@ export function __inspect(declaration: InspectDeclaration, initial: InspectValueinitial,get,set,+ committed,+ commit: (value) => {+ set(value);+ setCommitted(value);+ },});return get;