Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: enhance context menus and commands with new shortcuts and improved structure

konstantin-paulusdb9a6f668fab
diff --git a/apps/web/src/agent-chat/header-actions.tsx b/apps/web/src/agent-chat/header-actions.tsx
index cff40b6d..a08cc341 100644
--- a/apps/web/src/agent-chat/header-actions.tsx
+++ b/apps/web/src/agent-chat/header-actions.tsx
@@ -33,7 +33,7 @@ export function HeaderActions(props: HeaderActionsProps) {
>
<Icon name="plus-add" />
</TooltipTrigger>
- <TooltipContent>New chat</TooltipContent>
+ <TooltipContent shortcut="⇧⌘L">New chat</TooltipContent>
</Tooltip>
</div>
);
diff --git a/apps/web/src/components/commands/index.tsx b/apps/web/src/components/commands/index.tsx
index 3203f427..1ed3b39c 100644
--- a/apps/web/src/components/commands/index.tsx
+++ b/apps/web/src/components/commands/index.tsx
@@ -22,7 +22,7 @@ import { WindowCommands } from "./window";
export { CommandBar } from "./command-bar";
export { CommandPalette } from "./palette";
-export { CANVAS_MENU, NodeContextMenu, TIMELINE_MENU } from "./node-menu";
+export { CANVAS_MENU, CommandContextMenu, NodeContextMenu, TIMELINE_HEADER_MENU, TIMELINE_MENU } from "./node-menu";
export { ReloadWindowCommand } from "./reload-window";
/**
diff --git a/apps/web/src/components/commands/node-menu.tsx b/apps/web/src/components/commands/node-menu.tsx
index 37d6daa8..50906244 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"], ["toggle-ui", "open-chat", "actions"]],
+ empty: [["shortcut:paste", "shortcut:select-all"], ["toggle-ui", "toggle-timeline", "toggle-chat", "actions"]],
};
/**
@@ -76,9 +76,26 @@ export const TIMELINE_MENU: NodeMenuLayout = {
empty: [["shortcut:paste"]],
};
+/**
+ * The timeline header's: what its buttons do, and putting the timeline away
+ * (or bringing it back), which a double-click on it does too.
+ */
+export const TIMELINE_HEADER_MENU: string[][] = [
+ ["shortcut:toggle-playback", "shortcut:split"],
+ ["toggle-timeline"],
+];
+
/** Whether `command` would run over the selection rather than ask for a target. */
const offered = (command: RegisteredCommand) => (command.available?.() ?? true) && (command.ready?.() ?? true);
+/** `layout`'s commands that are on offer, sections left with none left out. */
+function resolve(commands: RegisteredCommand[], layout: string[][]): RegisteredCommand[][] {
+ const byId = new Map(commands.map((command) => [command.id, command]));
+ return layout
+ .map((ids) => ids.map((id) => byId.get(id)).filter((command) => command !== undefined).filter(offered))
+ .filter((section) => section.length > 0);
+}
+
export type NodeContextMenuProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, "onContextMenu"> & {
/** The nodes a right-click at `event` is on; empty over nothing. */
pick(event: MouseEvent): Entity[];
@@ -90,9 +107,8 @@ export type NodeContextMenuProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, "onC
export function NodeContextMenu(props: NodeContextMenuProps) {
const [local, rest] = splitProps(props, ["pick", "layout", "children"]);
const world = useWorld();
- const { commands, execute } = useCommands();
+ const { commands } = useCommands();
const { nodes } = useSelection();
- const [frozen, setFrozen] = createSignal<RegisteredCommand[][] | null>(null);
const select = (event: MouseEvent) => {
const editor = getDocumentEditor(world);
@@ -114,27 +130,68 @@ export function NodeContextMenu(props: NodeContextMenuProps) {
* right-click just made shows up in it a frame after the menu opens.
*/
const live = () => {
- const byId = new Map(commands().map((command) => [command.id, command]));
const layout = local.layout ?? CANVAS_MENU;
- return (nodes().length ? layout.nodes : layout.empty)
- .map((ids) => ids.map((id) => byId.get(id)).filter((command) => command !== undefined).filter(offered))
- .filter((section) => section.length > 0);
+ return resolve(commands(), nodes().length ? layout.nodes : layout.empty);
+ };
+
+ return (
+ <CommandMenu {...rest} sections={live} onContextMenu={select}>
+ {local.children}
+ </CommandMenu>
+ );
+}
+
+export type CommandContextMenuProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, "onContextMenu"> & {
+ /** What the menu lists, by command id, a rule between sections. */
+ layout: string[][];
+};
+
+/**
+ * A right-click menu of commands that work on no selection — a panel's
+ * header's, say. Unlike `NodeContextMenu`, the click leaves the selection be.
+ */
+export function CommandContextMenu(props: CommandContextMenuProps) {
+ const [local, rest] = splitProps(props, ["layout", "children"]);
+ const { commands } = useCommands();
+
+ const live = () => resolve(commands(), local.layout);
+
+ const prevent = (event: MouseEvent) => {
+ if (live().length === 0) event.preventDefault();
};
+ return (
+ <CommandMenu {...rest} sections={live} onContextMenu={prevent}>
+ {local.children}
+ </CommandMenu>
+ );
+}
+
+type CommandMenuProps = JSX.HTMLAttributes<HTMLDivElement> & {
+ /** What is on offer, followed while the menu is open. */
+ sections(): RegisteredCommand[][];
+ onContextMenu(event: MouseEvent): void;
+};
+
+function CommandMenu(props: CommandMenuProps) {
+ const [local, rest] = splitProps(props, ["sections", "children"]);
+ const { execute } = useCommands();
+ const [frozen, setFrozen] = createSignal<RegisteredCommand[][] | null>(null);
+
/**
* Holds the list as it stands until the menu is open again: a command run
* from it changes the selection, and the menu should not change under the
* pointer while it fades out.
*/
const freeze = () => {
- if (frozen() === null) setFrozen(live());
+ if (frozen() === null) setFrozen(local.sections());
};
- const sections = () => frozen() ?? live();
+ const sections = () => frozen() ?? local.sections();
return (
<ContextMenu onOpenChange={(open) => (open ? setFrozen(null) : freeze())}>
- <ContextMenuTrigger {...rest} onContextMenu={select}>
+ <ContextMenuTrigger {...rest}>
{local.children}
</ContextMenuTrigger>
<ContextMenuPortal>
diff --git a/apps/web/src/components/commands/window.tsx b/apps/web/src/components/commands/window.tsx
index e0429dfe..4cb81936 100644
--- a/apps/web/src/components/commands/window.tsx
+++ b/apps/web/src/components/commands/window.tsx
@@ -3,13 +3,15 @@
* 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 { setActiveChat, setSidebarTab, sidebarTab } from "@/agent-chat/store";
import { useCommand, useCommands } from "@/context/commands";
import { useLayout } from "@/context/layout";
+import { useProject } from "@/context/project";
/** Showing and hiding the panels around the canvas, the chat, and the palette itself. */
export function WindowCommands() {
const layout = useLayout();
+ const project = useProject();
const { setPaletteOpen } = useCommands();
useCommand({
@@ -22,19 +24,68 @@ export function WindowCommands() {
run: layout.toggleUI,
});
+ const timelineShown = () => layout.uiVisible() && !layout.timelineMinimized();
+
+ // With the UI hidden the timeline is too, so showing it brings the UI back.
+ const toggleTimeline = () => {
+ if (timelineShown()) {
+ layout.toggleTimeline();
+ return;
+ }
+
+ if (!layout.uiVisible()) layout.toggleUI();
+ if (layout.timelineMinimized()) layout.toggleTimeline();
+ };
+
useCommand({
- id: "open-chat",
- title: "Open chat",
+ id: "toggle-timeline",
+ title: "Show/Hide timeline",
+ group: "Window",
+ icon: "sidebar-timeline",
+ keywords: ["panel", "tracks", "layers", "minimize", "toggle timeline"],
+ shortcut: ["⌘", "J"],
+ run: toggleTimeline,
+ });
+
+ const chatShown = () => layout.uiVisible() && sidebarTab() === "chat";
+
+ const showChat = () => {
+ 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());
+ };
+
+ const toggleChat = () => {
+ if (chatShown()) setSidebarTab("assets");
+ else showChat();
+ };
+
+ // What the chat header's plus does, from wherever the chat is.
+ const newChat = () => {
+ setActiveChat(project.id(), null);
+ showChat();
+ };
+
+ useCommand({
+ id: "toggle-chat",
+ title: "Show/Hide chat",
group: "Window",
icon: "ask-chat",
- 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());
- },
+ keywords: ["open chat", "agent", "assistant", "message", "claude"],
+ shortcut: ["⌘", "L"],
+ run: toggleChat,
+ });
+
+ useCommand({
+ id: "new-chat",
+ title: "New chat thread",
+ group: "Window",
+ icon: "plus-add",
+ keywords: ["new thread", "conversation", "agent", "assistant", "claude"],
+ shortcut: ["⇧", "⌘", "L"],
+ run: newChat,
});
useCommand({
@@ -47,15 +98,39 @@ export function WindowCommands() {
run: () => setPaletteOpen(true),
});
- // ⌘\ wherever focus is, a field included, as ⌘K is: ahead of the editor,
- // which would otherwise record the key as held.
+ // ⌘\, ⌘J, ⌘L and ⇧⌘L 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;
+ if (!(event.metaKey || event.ctrlKey) || event.altKey) return;
+
+ if (event.shiftKey) {
+ if (event.key.toLowerCase() !== "l" && event.code !== "KeyL") return;
+
+ event.preventDefault();
+ event.stopPropagation();
+ newChat();
+ return;
+ }
+
+ if (event.key === "\\" || event.code === "Backslash") {
+ event.preventDefault();
+ event.stopPropagation();
+ layout.toggleUI();
+ return;
+ }
+
+ if (event.key.toLowerCase() === "j" || event.code === "KeyJ") {
+ event.preventDefault();
+ event.stopPropagation();
+ toggleTimeline();
+ return;
+ }
- event.preventDefault();
- event.stopPropagation();
- layout.toggleUI();
+ if (event.key.toLowerCase() === "l" || event.code === "KeyL") {
+ event.preventDefault();
+ event.stopPropagation();
+ toggleChat();
+ }
};
onMount(() => window.addEventListener("keydown", onKeyDown, true));
diff --git a/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx b/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx
index f13ef7c2..42517ead 100644
--- a/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx
+++ b/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx
@@ -52,9 +52,11 @@ export function ViewMenu() {
<DropdownMenuGroup>
<DropdownMenuItem onSelect={layout.toggleUI}>
Toggle UI
+ <DropdownMenuShortcut>⌘\</DropdownMenuShortcut>
</DropdownMenuItem>
<DropdownMenuItem onSelect={layout.toggleTimeline}>
Toggle timeline
+ <DropdownMenuShortcut>⌘J</DropdownMenuShortcut>
</DropdownMenuItem>
</DropdownMenuGroup>
</>
diff --git a/apps/web/src/components/timeline/layers/layers.tsx b/apps/web/src/components/timeline/layers/layers.tsx
index 15f5907e..a141efa5 100644
--- a/apps/web/src/components/timeline/layers/layers.tsx
+++ b/apps/web/src/components/timeline/layers/layers.tsx
@@ -35,6 +35,7 @@ import {
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from '@/components/ui/tooltip';
+import { CommandContextMenu, TIMELINE_HEADER_MENU } from '@/components/commands';
import { DEFAULT_CLIP_HEIGHT, RULER_HEIGHT } from '@/engine/timeline';
import { splitAtPlayhead } from '@/engine/split';
import { useDerived, useEditor, useTimelineIndex } from '@/engine/hooks';
@@ -150,9 +151,10 @@ export function Layers() {
style={{ 'grid-template-rows': `${RULER_HEIGHT}px 1fr` }}
data-timeline-layers-container
>
- <div
+ <CommandContextMenu
+ layout={TIMELINE_HEADER_MENU}
class="w-full z-10 flex flex-row gap-1 pl-2 pr-3 items-center text-muted-foreground select-none"
- on:dblclick={handleHeaderDoubleClick}
+ onDblClick={handleHeaderDoubleClick}
>
<Tooltip placement="top">
<TooltipTrigger<typeof Button>
@@ -271,7 +273,7 @@ export function Layers() {
<span class="text-xs font-mono font-thin ml-auto select-none">
{clock()}
</span>
- </div>
+ </CommandContextMenu>
<div data-timeline-layers-viewport class="relative h-full z-0 overflow-hidden">
<div
data-timeline-layers