Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: add window commands for UI toggling and chat access

konstantin-paulus9b3983d32a63
diff --git a/apps/web/src/agent-chat/composer.tsx b/apps/web/src/agent-chat/composer.tsx
index 31716d6e..4e85ba1f 100644
--- a/apps/web/src/agent-chat/composer.tsx
+++ b/apps/web/src/agent-chat/composer.tsx
@@ -105,6 +105,7 @@ export function Composer(props: ComposerProps) {
<textarea
ref={textarea}
+ data-chat-composer
value={props.text}
onInput={(event) => props.onText(event.currentTarget.value)}
onKeyDown={handleKeyDown}
diff --git a/apps/web/src/components/commands/index.tsx b/apps/web/src/components/commands/index.tsx
index 8a2eb60d..3203f427 100644
--- a/apps/web/src/components/commands/index.tsx
+++ b/apps/web/src/components/commands/index.tsx
@@ -18,6 +18,7 @@ import { ReuseSettingsCommand } from "./reuse-settings";
import { ShortcutCommands } from "./shortcuts";
import { ToolCommand } from "./tool";
import { UpscaleCommand } from "./upscale";
+import { WindowCommands } from "./window";
export { CommandBar } from "./command-bar";
export { CommandPalette } from "./palette";
@@ -26,8 +27,8 @@ export { ReloadWindowCommand } from "./reload-window";
/**
* The canvas's commands: what to generate, what the selected media can be
- * run through, the toolbar's tools, the keyboard shortcuts, and where else
- * the project folder can be opened.
+ * run through, the toolbar's tools, the keyboard shortcuts, where else
+ * the project folder can be opened, and the panels around the canvas.
*/
export function CanvasCommands() {
return (
@@ -58,6 +59,7 @@ export function CanvasCommands() {
<ShortcutCommands />
<LayerToggleCommands />
<ProjectFolderCommands />
+ <WindowCommands />
</>
);
}
diff --git a/apps/web/src/components/commands/node-menu.tsx b/apps/web/src/components/commands/node-menu.tsx
index f82dbf43..37d6daa8 100644
--- a/apps/web/src/components/commands/node-menu.tsx
+++ b/apps/web/src/components/commands/node-menu.tsx
@@ -56,7 +56,7 @@ export const CANVAS_MENU: NodeMenuLayout = {
MEDIA,
GENERATE,
],
- empty: [["shortcut:paste", "shortcut:select-all"]],
+ empty: [["shortcut:paste", "shortcut:select-all"], ["toggle-ui", "open-chat", "actions"]],
};
/**
diff --git a/apps/web/src/components/commands/palette.tsx b/apps/web/src/components/commands/palette.tsx
index ad1bada5..41cc222a 100644
--- a/apps/web/src/components/commands/palette.tsx
+++ b/apps/web/src/components/commands/palette.tsx
@@ -11,7 +11,7 @@ import { SECTIONS, useCommands } from "@/context/commands";
import type { LayerSection, LayeredCommand, RegisteredCommand } from "@/context/commands";
-const offered = (command: RegisteredCommand) => command.available?.() ?? true;
+const offered = (command: RegisteredCommand) => command.palette !== false && (command.available?.() ?? true);
/**
* The least score a match needs to be listed. cmdk matches letters anywhere
diff --git a/apps/web/src/components/commands/window.tsx b/apps/web/src/components/commands/window.tsx
new file mode 100644
index 00000000..0beef554
--- /dev/null
+++ b/apps/web/src/components/commands/window.tsx
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 { onCleanup, onMount } from "solid-js";
+import { setSidebarTab } from "@/agent-chat/store";
+import { useCommand, useCommands } from "@/context/commands";
+import { useLayout } from "@/context/layout";
+
+/** Showing and hiding the panels around the canvas, the chat, and the palette itself. */
+export function WindowCommands() {
+ const layout = useLayout();
+ const { setPaletteOpen } = useCommands();
+
+ useCommand({
+ id: "toggle-ui",
+ title: "Show/Hide UI",
+ group: "Window",
+ icon: "sidebar",
+ keywords: ["panels", "sidebar", "focus", "fullscreen", "toggle ui"],
+ shortcut: ["⌘", "\\"],
+ run: layout.toggleUI,
+ });
+
+ useCommand({
+ id: "open-chat",
+ title: "Open chat",
+ group: "Window",
+ keywords: ["agent", "assistant", "message", "claude"],
+ run: () => {
+ if (!layout.uiVisible()) layout.toggleUI();
+ setSidebarTab("chat");
+ // A composer that mounts with the tab focuses itself; one that was up
+ // already is focused here, once the menu that ran this has let go.
+ requestAnimationFrame(() => document.querySelector<HTMLTextAreaElement>("[data-chat-composer]")?.focus());
+ },
+ });
+
+ useCommand({
+ id: "actions",
+ title: "Actions…",
+ group: "Window",
+ shortcut: ["⌘", "K"],
+ palette: false,
+ run: () => setPaletteOpen(true),
+ });
+
+ // ⌘\ wherever focus is, a field included, as ⌘K is: ahead of the editor,
+ // which would otherwise record the key as held.
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (!(event.metaKey || event.ctrlKey) || event.shiftKey || event.altKey) return;
+ if (event.key !== "\\" && event.code !== "Backslash") return;
+
+ event.preventDefault();
+ event.stopPropagation();
+ layout.toggleUI();
+ };
+
+ onMount(() => window.addEventListener("keydown", onKeyDown, true));
+ onCleanup(() => window.removeEventListener("keydown", onKeyDown, true));
+
+ return null;
+}
diff --git a/apps/web/src/context/commands.tsx b/apps/web/src/context/commands.tsx
index 989e54f2..89b379e9 100644
--- a/apps/web/src/context/commands.tsx
+++ b/apps/web/src/context/commands.tsx
@@ -110,6 +110,11 @@ export type Command = CommandAction & {
order?: number;
/** Whether it is offered right now; always, when left out. */
available?(): boolean;
+ /**
+ * False keeps it out of the palette and its recents, for a command only a
+ * menu lists: the one that opens the palette itself.
+ */
+ palette?: false;
};
/** A command as registered: with the owner of the component that registered it. */
@@ -154,7 +159,9 @@ export function CommandsProvider(props: { children: JSX.Element }) {
};
const execute = (command: RegisteredCommand) => {
- setRecents([command.id, ...recents().filter((id) => id !== command.id)].slice(0, RECENTS_KEPT));
+ if (command.palette !== false) {
+ setRecents([command.id, ...recents().filter((id) => id !== command.id)].slice(0, RECENTS_KEPT));
+ }
if (command.layer) {
setLayer({ ...command, layer: command.layer });
return;