Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions apps/server/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ResolvedKeybindingsConfig,
type ServerConfigIssue,
} from "@t3tools/contracts";
import { DEFAULT_KEYBINDINGS } from "@t3tools/shared/keybindings";
import { Mutable } from "effect/Types";
import {
Array,
Expand Down Expand Up @@ -64,17 +65,7 @@ type WhenToken =
| { type: "lparen" }
| { type: "rparen" };

export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
{ key: "mod+j", command: "terminal.toggle" },
{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },
{ key: "mod+n", command: "terminal.new", when: "terminalFocus" },
{ key: "mod+w", command: "terminal.close", when: "terminalFocus" },
{ key: "mod+d", command: "diff.toggle", when: "!terminalFocus" },
{ key: "mod+n", command: "chat.new", when: "!terminalFocus" },
{ key: "mod+shift+o", command: "chat.new", when: "!terminalFocus" },
{ key: "mod+shift+n", command: "chat.newLocal", when: "!terminalFocus" },
{ key: "mod+o", command: "editor.openFavorite" },
];
export { DEFAULT_KEYBINDINGS };

function normalizeKeyToken(token: string): string {
if (token === "space") return " ";
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/appSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";

import {
DEFAULT_SHOW_HEADER_KEYBINDINGS_BUTTON,
DEFAULT_TIMESTAMP_FORMAT,
getAppModelOptions,
normalizeCustomModelSlugs,
Expand Down Expand Up @@ -64,3 +65,9 @@ describe("timestamp format defaults", () => {
expect(DEFAULT_TIMESTAMP_FORMAT).toBe("locale");
});
});

describe("header keybindings button defaults", () => {
it("shows the chat header keybindings button by default", () => {
expect(DEFAULT_SHOW_HEADER_KEYBINDINGS_BUTTON).toBe(true);
});
});
4 changes: 4 additions & 0 deletions apps/web/src/appSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const MAX_CUSTOM_MODEL_LENGTH = 256;
export const TIMESTAMP_FORMAT_OPTIONS = ["locale", "12-hour", "24-hour"] as const;
export type TimestampFormat = (typeof TIMESTAMP_FORMAT_OPTIONS)[number];
export const DEFAULT_TIMESTAMP_FORMAT: TimestampFormat = "locale";
export const DEFAULT_SHOW_HEADER_KEYBINDINGS_BUTTON = true;
const BUILT_IN_MODEL_SLUGS_BY_PROVIDER: Record<ProviderKind, ReadonlySet<string>> = {
codex: new Set(getModelOptions("codex").map((option) => option.slug)),
};
Expand All @@ -28,6 +29,9 @@ const AppSettingsSchema = Schema.Struct({
enableAssistantStreaming: Schema.Boolean.pipe(
Schema.withConstructorDefault(() => Option.some(false)),
),
showHeaderKeybindingsButton: Schema.Boolean.pipe(
Schema.withConstructorDefault(() => Option.some(DEFAULT_SHOW_HEADER_KEYBINDINGS_BUTTON)),
),
timestampFormat: Schema.Literals(["locale", "12-hour", "24-hour"]).pipe(
Schema.withConstructorDefault(() => Option.some(DEFAULT_TIMESTAMP_FORMAT)),
),
Expand Down
65 changes: 7 additions & 58 deletions apps/web/src/components/ProjectScriptsControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import {
} from "lucide-react";
import React, { type FormEvent, type KeyboardEvent, useCallback, useMemo, useState } from "react";

import {
keybindingValueForCommand,
decodeProjectScriptKeybindingRule,
} from "~/lib/projectScriptKeybindings";
import { decodeProjectScriptKeybindingRule } from "~/lib/projectScriptKeybindings";
import {
commandForProjectScript,
nextProjectScriptId,
primaryProjectScript,
} from "~/projectScripts";
import { shortcutLabelForCommand } from "~/keybindings";
import { isMacPlatform } from "~/lib/utils";
import {
keybindingValueForCommand,
keybindingValueFromEvent,
shortcutLabelForCommand,
} from "~/keybindings";
import {
AlertDialog,
AlertDialogClose,
Expand Down Expand Up @@ -96,57 +96,6 @@ interface ProjectScriptsControlProps {
onDeleteScript: (scriptId: string) => Promise<void> | void;
}

function normalizeShortcutKeyToken(key: string): string | null {
const normalized = key.toLowerCase();
if (
normalized === "meta" ||
normalized === "control" ||
normalized === "ctrl" ||
normalized === "shift" ||
normalized === "alt" ||
normalized === "option"
) {
return null;
}
if (normalized === " ") return "space";
if (normalized === "escape") return "esc";
if (normalized === "arrowup") return "arrowup";
if (normalized === "arrowdown") return "arrowdown";
if (normalized === "arrowleft") return "arrowleft";
if (normalized === "arrowright") return "arrowright";
if (normalized.length === 1) return normalized;
if (normalized.startsWith("f") && normalized.length <= 3) return normalized;
if (normalized === "enter" || normalized === "tab" || normalized === "backspace") {
return normalized;
}
if (normalized === "delete" || normalized === "home" || normalized === "end") {
return normalized;
}
if (normalized === "pageup" || normalized === "pagedown") return normalized;
return null;
}

function keybindingFromEvent(event: KeyboardEvent<HTMLInputElement>): string | null {
const keyToken = normalizeShortcutKeyToken(event.key);
if (!keyToken) return null;

const parts: string[] = [];
if (isMacPlatform(navigator.platform)) {
if (event.metaKey) parts.push("mod");
if (event.ctrlKey) parts.push("ctrl");
} else {
if (event.ctrlKey) parts.push("mod");
if (event.metaKey) parts.push("meta");
}
if (event.altKey) parts.push("alt");
if (event.shiftKey) parts.push("shift");
if (parts.length === 0) {
return null;
}
parts.push(keyToken);
return parts.join("+");
}

export default function ProjectScriptsControl({
scripts,
keybindings,
Expand Down Expand Up @@ -186,7 +135,7 @@ export default function ProjectScriptsControl({
setKeybinding("");
return;
}
const next = keybindingFromEvent(event);
const next = keybindingValueFromEvent(event, navigator.platform);
if (!next) return;
setKeybinding(next);
};
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/components/chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
import { memo } from "react";
import GitActionsControl from "../GitActionsControl";
import { DiffIcon } from "lucide-react";
import { useAppSettings } from "~/appSettings";
import { Badge } from "../ui/badge";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import ProjectScriptsControl, { type NewProjectScriptInput } from "../ProjectScriptsControl";
import { Toggle } from "../ui/toggle";
import { SidebarTrigger } from "../ui/sidebar";
import { KeybindingsControl } from "./KeybindingsControl";
import { OpenInPicker } from "./OpenInPicker";

interface ChatHeaderProps {
Expand Down Expand Up @@ -53,6 +55,8 @@ export const ChatHeader = memo(function ChatHeader({
onDeleteProjectScript,
onToggleDiff,
}: ChatHeaderProps) {
const { settings } = useAppSettings();

return (
<div className="flex min-w-0 flex-1 items-center gap-2">
<div className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden sm:gap-3">
Expand Down Expand Up @@ -86,6 +90,9 @@ export const ChatHeader = memo(function ChatHeader({
onDeleteScript={onDeleteProjectScript}
/>
)}
{settings.showHeaderKeybindingsButton ? (
<KeybindingsControl keybindings={keybindings} triggerLabel="Keys" />
) : null}
{activeProjectName && (
<OpenInPicker
keybindings={keybindings}
Expand Down
Loading