authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-02-15 14:33:56-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-02-15 15:51:05-08:00
log0a5aaf3e0e64fa70e90541c93842296e97d653a6
tree57843fdca667d988d879414cbe43dddc23c547dd
parent3d7ef8a833dbd38f847c4ba212ebee61eb53a9f1

tidy up


4 files changed, 30 insertions(+), 28 deletions(-)

apps/web/src/components/ChatView.tsx+7-8
......@@ -23,10 +23,7 @@ import {
2323 useState,
2424} from "react";
2525import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
26import {
27 gitBranchesQueryOptions,
28 gitCreateWorktreeMutationOptions,
29} from "~/lib/gitReactQuery";
26import { gitBranchesQueryOptions, gitCreateWorktreeMutationOptions } from "~/lib/gitReactQuery";
3027import { serverConfigQueryOptions } from "~/lib/serverReactQuery";
3128
3229import { isElectron } from "../env";
......@@ -79,7 +76,7 @@ import { Separator } from "./ui/separator";
7976import { Group, GroupSeparator } from "./ui/group";
8077import { Menu, MenuItem, MenuPopup, MenuShortcut, MenuTrigger } from "./ui/menu";
8178import { CursorIcon, Icon } from "./Icons";
82import { cn } from "~/lib/utils";
79import { cn, isMacPlatform, isWindowsPlatform } from "~/lib/utils";
8380import { Badge } from "./ui/badge";
8481
8582function formatMessageMeta(createdAt: string, duration: string | null): string {
......@@ -140,7 +137,9 @@ export default function ChatView() {
140137 const { state, dispatch } = useStore();
141138 const api = useNativeApi();
142139 const queryClient = useQueryClient();
143 const createWorktreeMutation = useMutation(gitCreateWorktreeMutationOptions({ api, queryClient }));
140 const createWorktreeMutation = useMutation(
141 gitCreateWorktreeMutationOptions({ api, queryClient }),
142 );
144143 const [prompt, setPrompt] = useState("");
145144 const [composerImages, setComposerImages] = useState<ComposerImageAttachment[]>([]);
146145 const [isDragOverComposer, setIsDragOverComposer] = useState(false);
......@@ -1533,9 +1532,9 @@ function OpenInPicker({ keybindings }: { keybindings: ResolvedKeybindingsConfig
15331532 value: "cursor",
15341533 },
15351534 {
1536 label: navigator.platform.includes("Mac")
1535 label: isMacPlatform(navigator.platform)
15371536 ? "Finder"
1538 : navigator.platform.includes("Win")
1537 : isWindowsPlatform(navigator.platform)
15391538 ? "Explorer"
15401539 : "Files",
15411540 Icon: FolderClosedIcon,
apps/web/src/keybindings.ts+14-16
......@@ -4,6 +4,7 @@ import {
44 type KeybindingWhenNode,
55 type ResolvedKeybindingsConfig,
66} from "@t3tools/contracts";
7import { isMacPlatform } from "./lib/utils";
78
89export interface ShortcutEventLike {
910 key: string;
......@@ -19,17 +20,11 @@ export interface ShortcutMatchContext {
1920 [key: string]: boolean;
2021}
2122
22export type ResolvedKeybindings = ResolvedKeybindingsConfig;
23
2423interface ShortcutMatchOptions {
2524 platform?: string;
2625 context?: Partial<ShortcutMatchContext>;
2726}
2827
29function isMacPlatform(platform: string): boolean {
30 return /mac|iphone|ipad|ipod/i.test(platform);
31}
32
3328function normalizeEventKey(key: string): string {
3429 const normalized = key.toLowerCase();
3530 if (normalized === "esc") return "escape";
......@@ -83,7 +78,7 @@ function evaluateWhenNode(node: KeybindingWhenNode, context: ShortcutMatchContex
8378}
8479
8580function matchesWhenClause(
86 whenAst: ResolvedKeybindings[number]["whenAst"],
81 whenAst: ResolvedKeybindingsConfig[number]["whenAst"],
8782 context: ShortcutMatchContext,
8883): boolean {
8984 if (!whenAst) return true;
......@@ -92,7 +87,7 @@ function matchesWhenClause(
9287
9388function matchesCommandShortcut(
9489 event: ShortcutEventLike,
95 keybindings: ResolvedKeybindings,
90 keybindings: ResolvedKeybindingsConfig,
9691 command: KeybindingCommand,
9792 options?: ShortcutMatchOptions,
9893): boolean {
......@@ -101,7 +96,7 @@ function matchesCommandShortcut(
10196
10297function resolveShortcutCommand(
10398 event: ShortcutEventLike,
104 keybindings: ResolvedKeybindings,
99 keybindings: ResolvedKeybindingsConfig,
105100 options?: ShortcutMatchOptions,
106101): KeybindingCommand | null {
107102 const platform = resolvePlatform(options);
......@@ -128,7 +123,10 @@ function formatShortcutKeyLabel(key: string): string {
128123 return key.slice(0, 1).toUpperCase() + key.slice(1);
129124}
130125
131export function formatShortcutLabel(shortcut: KeybindingShortcut, platform = navigator.platform): string {
126export function formatShortcutLabel(
127 shortcut: KeybindingShortcut,
128 platform = navigator.platform,
129): string {
132130 const keyLabel = formatShortcutKeyLabel(shortcut.key);
133131 const useMetaForMod = isMacPlatform(platform);
134132 const showMeta = shortcut.metaKey || (shortcut.modKey && useMetaForMod);
......@@ -150,7 +148,7 @@ export function formatShortcutLabel(shortcut: KeybindingShortcut, platform = nav
150148}
151149
152150export function shortcutLabelForCommand(
153 keybindings: ResolvedKeybindings,
151 keybindings: ResolvedKeybindingsConfig,
154152 command: KeybindingCommand,
155153 platform = navigator.platform,
156154): string | null {
......@@ -164,7 +162,7 @@ export function shortcutLabelForCommand(
164162
165163export function isTerminalToggleShortcut(
166164 event: ShortcutEventLike,
167 keybindings: ResolvedKeybindings,
165 keybindings: ResolvedKeybindingsConfig,
168166 options?: ShortcutMatchOptions,
169167): boolean {
170168 return matchesCommandShortcut(event, keybindings, "terminal.toggle", options);
......@@ -172,7 +170,7 @@ export function isTerminalToggleShortcut(
172170
173171export function isTerminalSplitShortcut(
174172 event: ShortcutEventLike,
175 keybindings: ResolvedKeybindings,
173 keybindings: ResolvedKeybindingsConfig,
176174 options?: ShortcutMatchOptions,
177175): boolean {
178176 return matchesCommandShortcut(event, keybindings, "terminal.split", options);
......@@ -180,7 +178,7 @@ export function isTerminalSplitShortcut(
180178
181179export function isTerminalNewShortcut(
182180 event: ShortcutEventLike,
183 keybindings: ResolvedKeybindings,
181 keybindings: ResolvedKeybindingsConfig,
184182 options?: ShortcutMatchOptions,
185183): boolean {
186184 return matchesCommandShortcut(event, keybindings, "terminal.new", options);
......@@ -188,7 +186,7 @@ export function isTerminalNewShortcut(
188186
189187export function isChatNewShortcut(
190188 event: ShortcutEventLike,
191 keybindings: ResolvedKeybindings,
189 keybindings: ResolvedKeybindingsConfig,
192190 options?: ShortcutMatchOptions,
193191): boolean {
194192 return matchesCommandShortcut(event, keybindings, "chat.new", options);
......@@ -196,7 +194,7 @@ export function isChatNewShortcut(
196194
197195export function isOpenFavoriteEditorShortcut(
198196 event: ShortcutEventLike,
199 keybindings: ResolvedKeybindings,
197 keybindings: ResolvedKeybindingsConfig,
200198 options?: ShortcutMatchOptions,
201199): boolean {
202200 return matchesCommandShortcut(event, keybindings, "editor.openFavorite", options);
apps/web/src/lib/utils.ts+8
......@@ -4,3 +4,11 @@ import { twMerge } from "tailwind-merge";
44export function cn(...inputs: CxOptions) {
55 return twMerge(cx(inputs));
66}
7
8export function isMacPlatform(platform: string): boolean {
9 return /mac|iphone|ipad|ipod/i.test(platform);
10}
11
12export function isWindowsPlatform(platform: string): boolean {
13 return /win|windows/i.test(platform);
14}
apps/web/src/terminal-links.ts+1-4
......@@ -1,4 +1,5 @@
11import { EDITORS, type EditorId } from "@t3tools/contracts";
2import { isMacPlatform } from "./lib/utils";
23
34export type TerminalLinkKind = "url" | "path";
45
......@@ -15,10 +16,6 @@ const FILE_PATH_PATTERN =
1516const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;
1617const LAST_EDITOR_KEY = "t3code:last-editor";
1718
18function isMacPlatform(platform: string): boolean {
19 return /mac|iphone|ipad|ipod/i.test(platform);
20}
21
2219function trimClosingDelimiters(value: string): string {
2320 let output = value.replace(TRAILING_PUNCTUATION_PATTERN, "");
2421 if (output.length === 0) return output;