@devries-cameron20 / t3code-1 / commits / a760a3a965
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): keyboard-opened message link menus select their first item (#24889)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 14, 2026 at 02:06 UTC a760a3a965705f12e38be700cd3a144fc5cf2c35
9 files changed +90 -9
apps/desktop/src/electron/ElectronMenu.ts
+7 -2
@@ -1,4 +1,4 @@
1 -import type { ContextMenuItem } from "@t3tools/contracts";
1 +import type { ContextMenuItem, ContextMenuSource } from "@t3tools/contracts";
2 import * as HostProcess from "@t3tools/shared/HostProcess";
3 import * as Context from "effect/Context";
4 import * as Effect from "effect/Effect";
@@ -17,6 +17,7 @@ export interface ElectronMenuContextInput {
17 readonly window: Electron.BrowserWindow;
18 readonly items: readonly ContextMenuItem[];
19 readonly position: Option.Option<ElectronMenuPosition>;
20 + readonly source: Option.Option<ContextMenuSource>;
21 }
22
23 export interface ElectronMenuTemplateInput {
@@ -259,7 +260,11 @@ export const make = Effect.gen(function* () {
260 callback: () => complete(Option.none()),
261 }),
262 });
262 - menu.popup(popupOptions);
263 + menu.popup(
264 + Option.isSome(input.source)
265 + ? { ...popupOptions, sourceType: input.source.value }
266 + : popupOptions,
267 + );
268 } catch (cause) {
269 if (completed) {
270 return;
apps/desktop/src/ipc/methods/window.ts
+3
@@ -1,5 +1,6 @@
1 import {
2 ContextMenuItemSchema,
3 + ContextMenuSource,
4 DesktopAppBrandingSchema,
5 DesktopEnvironmentBootstrapSchema,
6 DesktopMediaReadSchema,
@@ -59,6 +60,7 @@ const ContextMenuPosition = Schema.Struct({
60 const ContextMenuInput = Schema.Struct({
61 items: Schema.Array(ContextMenuItemSchema),
62 position: Schema.optionalKey(ContextMenuPosition),
63 + source: Schema.optionalKey(ContextMenuSource),
64 });
65
66 function toWebSocketBaseUrl(httpBaseUrl: URL): string {
@@ -340,6 +342,7 @@ export const showContextMenu = DesktopIpc.makeIpcMethod({
342 window: window.value,
343 items: input.items,
344 position: Option.fromNullishOr(input.position),
345 + source: Option.fromNullishOr(input.source),
346 });
347 return Option.getOrNull(selectedItemId);
348 }),
apps/desktop/src/preload.ts
+2 -1
@@ -244,10 +244,11 @@ contextBridge.exposeInMainWorld("desktopBridge", {
244 ipcRenderer.invoke(IpcChannels.PICK_PROJECT_FAVICON_CHANNEL, initialPath),
245 pickThemeFiles: () => ipcRenderer.invoke(IpcChannels.PICK_THEME_FILES_CHANNEL, undefined),
246 setTheme: (theme) => ipcRenderer.invoke(IpcChannels.SET_THEME_CHANNEL, theme),
247 - showContextMenu: (items, position) =>
247 + showContextMenu: (items, position, source) =>
248 ipcRenderer.invoke(IpcChannels.CONTEXT_MENU_CHANNEL, {
249 items,
250 ...(position === undefined ? {} : { position }),
251 + ...(source === undefined ? {} : { source }),
252 }),
253 receiveProviderAuthCallback: (url: string) =>
254 ipcRenderer.invoke(IpcChannels.RECEIVE_PROVIDER_AUTH_CALLBACK_CHANNEL, url),
apps/web/src/components/ChatMarkdown.permissions.browser.test.tsx
+44
@@ -9,6 +9,7 @@ import {
9 } from "@t3tools/contracts";
10 import { AsyncResult } from "effect/reactivity";
11 import { expect, it, vi } from "vite-plus/test";
12 +import { userEvent } from "vite-plus/test/browser";
13
14 import { act, render } from "../../test/render";
15 import { useRightPanelStore } from "../rightPanelStore";
@@ -102,6 +103,7 @@ vi.mock(import("@t3tools/client-runtime/change-request-links"), async (original)
103 }));
104
105 import ChatMarkdown from "./ChatMarkdown";
106 +import { MarkdownFileLink } from "./chat/MarkdownFileLink";
107
108 const threadRef = {
109 environmentId: EnvironmentId.make("selected"),
@@ -196,6 +198,19 @@ it("removes host actions after revocation while keeping file preview and copying
198 expect(state.openEditor).not.toHaveBeenCalled();
199 });
200
201 +it.each(["[Docs](https://example.com/docs)", "[Readme](docs/readme.md)"])(
202 + "tells the native menu for %s whether the keyboard opened it",
203 + async (text) => {
204 + using _setup = setup();
205 + await using screen = await renderMarkdown(text);
206 + screen.anchor().focus();
207 + await userEvent.keyboard("{Shift>}{F10}{/Shift}");
208 + await vi.waitFor(() => expect(state.choose.mock.lastCall?.[2]).toBe("keyboard"));
209 + await userEvent.click(screen.anchor(), { button: "right" });
210 + await vi.waitFor(() => expect(state.choose.mock.lastCall?.[2]).toBe("mouse"));
211 + },
212 +);
213 +
214 it("does not launch an editor after revocation during a native context menu", async () => {
215 using _setup = setup();
216 let choose: (action: string) => void = () => {
@@ -278,3 +293,32 @@ it.each(["link-to-thread", "unlink-from-thread"])(
293 );
294 },
295 );
296 +
297 +it("preserves keyboard activation of a file-options button", async () => {
298 + using _setup = setup();
299 + await using screen = await render(
300 + <MarkdownFileLink
301 + environmentId={null}
302 + href="readme.md"
303 + targetPath="readme.md"
304 + iconPath="readme.md"
305 + workspaceRelativePath="readme.md"
306 + panelPath={null}
307 + label="Readme"
308 + copyMarkdown="[Readme](readme.md)"
309 + theme="dark"
310 + onOpenInPanel={vi.fn()}
311 + resolveCopyPaths={async () => ({ relativePath: "readme.md", fullPath: "/work/readme.md" })}
312 + openInEditorMenuLabel="Open in editor"
313 + />,
314 + );
315 + const button = screen.container.querySelector("button")!;
316 + button.focus();
317 + for (const key of ["{Enter}", " "]) {
318 + await userEvent.keyboard(key);
319 + await vi.waitFor(() => expect(state.choose.mock.lastCall?.[2]).toBe("keyboard"));
320 + state.choose.mockClear();
321 + }
322 + await userEvent.click(button);
323 + await vi.waitFor(() => expect(state.choose.mock.lastCall?.[2]).toBe("mouse"));
324 +});
apps/web/src/components/ChatMarkdown.tsx
+3 -1
@@ -126,6 +126,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
126 import { Button } from "./ui/button";
127 import { stackedThreadToast, toastManager } from "./ui/toast";
128 import { recordVisitForThread } from "../browserHistoryStore";
129 +import { contextMenuSourceOf } from "../contextMenuSource";
130 import {
131 PreferredEditorEnvironmentRequiredError,
132 useOpenInPreferredEditor,
@@ -1319,6 +1320,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
1320 event.stopPropagation();
1321 const api = readLocalApi();
1322 if (!api) return;
1323 + const source = contextMenuSourceOf(event);
1324 const threadLinkAction = !canOperateHost
1325 ? undefined
1326 : linkedThreadPullRequestFor(href) !== null
@@ -1331,7 +1333,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
1333 canOpenInPreview,
1334 threadLinkAction,
1335 position: { x: event.clientX, y: event.clientY },
1334 - showContextMenu: (items, position) => api.contextMenu.show(items, position),
1336 + showContextMenu: (items, position) => api.contextMenu.show(items, position, source),
1337 openInPreview: async (target) => {
1338 const result = await openExternalLinkInPreview(target);
1339 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
apps/web/src/components/chat/MarkdownFileLink.tsx
+8 -3
@@ -5,9 +5,10 @@ import {
5 squashAtomCommandFailure,
6 type AtomCommandResult,
7 } from "@t3tools/client-runtime/state/runtime";
8 -import type { EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
8 +import type { ContextMenuSource, EnvironmentId, ScopedThreadRef } from "@t3tools/contracts";
9 import { memo, useState, type MouseEvent as ReactMouseEvent } from "react";
10
11 +import { contextMenuSourceOf } from "../../contextMenuSource";
12 import { readLocalApi } from "../../localApi";
13 import { cn } from "../../lib/utils";
14 import { shouldOpenMarkdownFileLinkInEditor } from "../../markdown-links";
@@ -235,7 +236,10 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
236 });
237 };
238
238 - const showFileContextMenu = async (position: { x: number; y: number }) => {
239 + const showFileContextMenu = async (
240 + position: { x: number; y: number },
241 + source: ContextMenuSource,
242 + ) => {
243 const api = readLocalApi();
244 if (!api) return;
245
@@ -252,6 +256,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
256 ...copyItems.map(({ id, label }) => ({ id, label })),
257 ] as const,
258 position,
259 + source,
260 );
261
262 if (clicked === "preview-media") {
@@ -297,7 +302,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
302 return { x: bounds.left, y: bounds.bottom };
303 })()
304 : { x: event.clientX, y: event.clientY };
300 - void showFileContextMenu(position);
305 + void showFileContextMenu(position, contextMenuSourceOf(event));
306 };
307
308 const canOpenInEditor = onOpen !== undefined;
apps/web/src/contextMenuSource.ts new
+8
@@ -0,0 +1,8 @@
1 +import type { ContextMenuSource } from "@t3tools/contracts";
2 +
3 +// Chromium uses no button for keyboard context menus and zero clicks for keyboard activation.
4 +export function contextMenuSourceOf(
5 + event: Pick<MouseEvent, "type" | "button" | "detail">,
6 +): ContextMenuSource {
7 + return (event.type === "click" ? event.detail === 0 : event.button === -1) ? "keyboard" : "mouse";
8 +}
apps/web/src/localApi.ts
+8 -2
@@ -1,4 +1,9 @@
1 -import type { ConfirmDialogOptions, ContextMenuItem, LocalApi } from "@t3tools/contracts";
1 +import type {
2 + ConfirmDialogOptions,
3 + ContextMenuItem,
4 + ContextMenuSource,
5 + LocalApi,
6 +} from "@t3tools/contracts";
7
8 import { isWebUrl } from "./browser/webUrl";
9 import { requestConfirmDialog } from "./confirmDialog";
@@ -45,9 +50,10 @@ export function createLocalApi(): LocalApi {
50 show: async <T extends string>(
51 items: readonly ContextMenuItem<T>[],
52 position?: { x: number; y: number },
53 + source?: ContextMenuSource,
54 ): Promise<T | null> => {
55 if (window.desktopBridge) {
50 - return window.desktopBridge.showContextMenu(items, position) as Promise<T | null>;
56 + return window.desktopBridge.showContextMenu(items, position, source) as Promise<T | null>;
57 }
58 return showContextMenuFallback(items, position);
59 },
packages/contracts/src/ipc.ts
+7
@@ -68,6 +68,11 @@ export const ContextMenuItemSchema: Schema.Codec<ContextMenuItemSchemaType> = Sc
68 ),
69 });
70
71 +// Native menus opened from the keyboard select their first item, which is what
72 +// moves a screen reader into the menu. Electron assumes a mouse unless told.
73 +export const ContextMenuSource = Schema.Literals(["mouse", "keyboard"]);
74 +export type ContextMenuSource = typeof ContextMenuSource.Type;
75 +
76 export type DesktopUpdateStatus =
77 | "disabled"
78 | "idle"
@@ -1135,6 +1140,7 @@ export interface DesktopBridge {
1140 showContextMenu: <T extends string>(
1141 items: readonly ContextMenuItem<T>[],
1142 position?: { x: number; y: number },
1143 + source?: ContextMenuSource,
1144 ) => Promise<T | null>;
1145 receiveProviderAuthCallback: (authorizationUrl: string) => Promise<string>;
1146 cancelProviderAuthCallback: (authorizationUrl: string) => Promise<void>;
@@ -1355,6 +1361,7 @@ export interface LocalApi {
1361 show: <T extends string>(
1362 items: readonly ContextMenuItem<T>[],
1363 position?: { x: number; y: number },
1364 + source?: ContextMenuSource,
1365 ) => Promise<T | null>;
1366 close: () => Promise<void>;
1367 };