The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Layers: arrow keys stay with focused controls; tool versions wait for autosave
Claude7b3b3e1e17b0
diff --git a/src/components/layers/layers-editor.tsx b/src/components/layers/layers-editor.tsxindex 54b00901..805f11ff 100644--- a/src/components/layers/layers-editor.tsx+++ b/src/components/layers/layers-editor.tsx@@ -35,6 +35,9 @@ import { TopBar, type SaveState } from "./top-bar";import { LayersRequestError, saveCover, saveDoc, useLayerActions, useLayerProject } from "./use-layers";const typing = (t: EventTarget | null) => t instanceof HTMLElement && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName));+/** Focus is on a control that uses the arrow keys itself. */+const widget = (t: EventTarget | null) =>+ t instanceof HTMLElement && !!t.closest('[role="radio"],[role="slider"],[role="menuitem"],[role="menu"],[role="tab"],[role="option"],[role="dialog"],[data-reorder]');/** The document is still just the image it was opened on (models can take the original file as is). */function pristine(doc: LayerDoc): boolean {@@ -135,14 +138,28 @@ function Editor({ view, refetch, models }: { view: LayerProjectView; refetch: ()// ---- Autosave into the head version (debounced; flushed with keepalive when leaving).const pending = useRef<LayerDoc | null>(null);+ /** The save in flight: a tool's version waits for it, so the two never cross. */+ const saving = useRef<Promise<unknown>>(Promise.resolve());useEffect(() => {if (doc === savedRef.current) return;pending.current = doc;setSave("dirty");const t = setTimeout(async () => {setSave("saving");+ const put = async (): Promise<void> => {+ const sentHead = headRef.current;+ try {+ await saveDoc(id, doc, sentHead);+ } catch (e) {+ // A tool's result became the head meanwhile (this tab): save onto the new head.+ if (e instanceof LayersRequestError && e.status === 409 && headRef.current !== sentHead) return put();+ throw e;+ }+ };+ const p = put();+ saving.current = p.catch(() => {});try {- await saveDoc(id, doc, headRef.current);+ await p;savedRef.current = doc;if (pending.current === doc) pending.current = null;setSave("saved");@@ -250,6 +267,7 @@ function Editor({ view, refetch, models }: { view: LayerProjectView; refetch: ()applying.current.add(j.id);queue.current = queue.current.then(async () => {try {+ await saving.current;const res = await applyJob(docRef.current, j, () => nanoid(8));const v = await actions.version(id, { doc: res.doc, label: j.label, jobId: j.id });setHead(v.headVersionId);@@ -387,7 +405,8 @@ function Editor({ view, refetch, models }: { view: LayerProjectView; refetch: ()}return;}- if (sel && e.key.startsWith("Arrow")) {+ // Arrow keys belong to the control that has focus (segmented controls, sliders, menus, the reorder handle).+ if (sel && e.key.startsWith("Arrow") && !widget(e.target)) {e.preventDefault();const step = e.shiftKey ? 10 : 1;const dx = e.key === "ArrowLeft" ? -step : e.key === "ArrowRight" ? step : 0;diff --git a/src/components/layers/layers-panel.tsx b/src/components/layers/layers-panel.tsxindex 8c7e2dc1..120fb19e 100644--- a/src/components/layers/layers-panel.tsx+++ b/src/components/layers/layers-panel.tsx@@ -336,6 +336,7 @@ function LayerRow({<buttontype="button"className="grid h-10 w-5 shrink-0 cursor-grab touch-none place-items-center rounded text-subtle-foreground hover:text-foreground active:cursor-grabbing"+ data-reorderaria-label={`Reorder ${node.name}. Use the up and down arrow keys to move it.`}onPointerDown={(e) => onDragHandle(e, node.id)}onKeyDown={(e) => {diff --git a/src/components/layers/stage.tsx b/src/components/layers/stage.tsxindex d2f39b80..041d9624 100644--- a/src/components/layers/stage.tsx+++ b/src/components/layers/stage.tsx@@ -173,7 +173,8 @@ export function Stage(p: StageProps) {useEffect(() => {const down = (e: KeyboardEvent) => {if (typing(e.target) || e.metaKey || e.ctrlKey || e.altKey) return;- if (e.code === "Space" && !e.repeat) {+ // Space presses a focused button; it pans only from the canvas or the page.+ if (e.code === "Space" && !e.repeat && !(e.target instanceof HTMLElement && e.target.closest("button, a, [role]"))) {setSpace(true);e.preventDefault();} else if (e.key === "+" || e.key === "=") zoomBy(1.25);diff --git a/src/components/layers/use-layers.ts b/src/components/layers/use-layers.tsindex 3dd8a769..6b82f45d 100644--- a/src/components/layers/use-layers.ts+++ b/src/components/layers/use-layers.ts@@ -1,7 +1,7 @@"use client";-import { useQuery, useQueryClient } from "@tanstack/react-query";-import { useCallback, useRef } from "react";+import { useQuery, useQueryClient, type QueryClient } from "@tanstack/react-query";+import { useCallback, useMemo, useRef } from "react";import { useGenerationEvents } from "@/lib/api";import type { LayerDoc, LayerJob, LayerJobInput, LayerProject, LayerProjectView } from "@/lib/layers";@@ -74,6 +74,10 @@ export function useLayerProject(id: string) {export function useLayerActions() {const qc = useQueryClient();+ return useMemo(() => layerActions(qc), [qc]);+}++function layerActions(qc: QueryClient) {const refreshList = () => void qc.invalidateQueries({ queryKey: ["layers"], exact: true });return {create: async (body: { source: string; width: number; height: number; name?: string; generationId?: string }) => {