Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(web): add explicit context-menu layout and focus options #8458

ClosedAdamulek123(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/8458/headopened View on GitHub

What Changed

Added backward-compatible context-menu options for compact layout, styled presentation, focus restoration, and owner cancellation. Menu accelerators now render and execute consistently in the browser fallback and Electron host.

Why

Callers with short action menus need a denser styled menu and deterministic cleanup, but those choices should stay in generic menu infrastructure. Existing callers keep the current default layout and native desktop behavior.

UI Changes

None for existing callers. This PR adds opt-in behavior and keeps every default unchanged.

Validation

  • Focused context-menu tests (34 passed)
  • Web, desktop, mobile, and contracts typechecks
  • Targeted lint passed with one pre-existing no-this-alias warning in the fallback test harness
  • git diff --check

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Existing UI defaults are unchanged

Implemented with GPT-5.6 Codex in T3 Code.


Note

Medium Risk Capture-phase keyboard handling and focus restoration change input behavior while menus are open; styled fallback on desktop bypasses native menus when opted in.

Overview Extends context menus with optional accelerator on items (contracts + IPC schema) and threads it through Electron native menus and the browser DOM fallback, where shortcuts render as <kbd> hints (including macOS symbol formatting) and run via capture-phase keydown so they win over focused terminals.

showContextMenuFallback and LocalApi.contextMenu.show gain opt-in layout: "compact", presentation: "styled" (use DOM menu even when a desktop bridge exists), restoreFocus (on-dismiss vs action selection), and AbortSignal cancellation. Dismissal also reacts to wheel outside the menu stack; contextMenu.close always tears down the styled fallback.

Existing callers keep default layout and native desktop presentation unless they pass the new options.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit efd2e945b4c26fbc6d782ecd231c3212f5b5ec10. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add accelerator, layout, and focus options to context menus

  • Extends ContextMenuItem with an optional accelerator string and LocalApi.contextMenu.show with an options object (layout, presentation, restoreFocus, signal).
  • The web fallback (showContextMenuFallback) now renders accelerator hints, matches keyboard events to menu items, supports a compact layout, dismisses on scroll, and manages lifecycle via AbortSignal with configurable focus restoration.
  • The Electron menu builder passes the accelerator through to native menu items.
  • createBrowserLocalApi.contextMenu.show forwards supported options to the fallback and can force the styled fallback on desktop with presentation: 'styled'; close now always calls dismissContextMenu.
  • Behavioral Change: dismissContextMenu is now called even when a desktop bridge exists; callers passing restoreFocus should verify focus handling matches expectations, particularly in apps/web/src/localApi.ts.
📊 Macroscope summarized efd2e94. 4 files reviewed, 5 issues evaluated, 0 issues filtered, 4 comments posted

🗂️ Filtered Issues

Before and after

Before:

https://github.com/user-attachments/assets/e47a978a-1aa1-4c2c-bbcb-c7e17d561c03

After:

https://github.com/user-attachments/assets/c0f1b032-8151-460e-a1a0-4ea4e549b741

    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 988e3cc3-c580-414c-bb9d-c79723bc424d

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. @@ -234,9 +283,20 @@
      283+ options?.restoreFocus !== false &&
      284+ (options?.restoreFocus !== "on-dismiss" || reason === "interaction") &&
      285+ shouldRestoreFocus &&
      286+ previouslyFocusedElement?.isConnected
      287+ ) {
      234288 previouslyFocusedElement.focus({ preventScroll: true });
      235289 }
      236290 resolve(result);
      237291 };
      238292
      293+ const onAbort = () => cleanup(null, "programmatic");
      294+
      239295 const onKeyDown = (event: KeyboardEvent) => {
      296+ if (event.isComposing) return;
      240297 if (event.key === "Escape") {
      241298 event.preventDefault();
      242- cleanup(null);
      299+ cleanup(null, "interaction");
      300+ return;
      301+ }
      302+ const action = contextMenuAcceleratorAction(items, event);
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium src/contextMenuFallback.ts:302

      Pressing an accelerator attached to a header: true item returns the header's id and closes the fallback menu, even though headers are non-interactive and are stripped from native menus. contextMenuAcceleratorAction must skip header items before matching their accelerators.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/contextMenuFallback.ts around line 302:
      
      Pressing an accelerator attached to a `header: true` item returns the header's `id` and closes the fallback menu, even though headers are non-interactive and are stripped from native menus. `contextMenuAcceleratorAction` must skip header items before matching their accelerators.
      @@ -234,9 +282,20 @@
      282+ if (
      283+ options?.restoreFocus !== false &&
      284+ (options?.restoreFocus !== "on-dismiss" || reason === "interaction") &&
      285+ shouldRestoreFocus &&
      286+ previouslyFocusedElement?.isConnected
      287+ ) {
      234288 previouslyFocusedElement.focus({ preventScroll: true });
      235289 }
      236290 resolve(result);
      237291 };
      238292
      293+ const onAbort = () => cleanup(null, "programmatic");
      294+
      239295 const onKeyDown = (event: KeyboardEvent) => {
      296+ if (event.isComposing) return;
      240297 if (event.key === "Escape") {
      241298 event.preventDefault();
      242- cleanup(null);
      299+ cleanup(null, "interaction");
      300+ return;
      301+ }
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium src/contextMenuFallback.ts:297

      Pressing Escape closes the menu but also reaches GhosttyTerminalSurface.onKeyDown, so an interactive terminal command is cancelled. preventDefault() does not stop propagation; call stopPropagation() before cleanup, as for accelerator actions.

      Suggested change
      297- if (event.key === "Escape") {
      298- event.preventDefault();
      299- cleanup(null, "interaction");
      300- return;
      301- }
      297+ if (event.key === "Escape") {
      298+ event.preventDefault();
      299+ event.stopPropagation();
      300+ cleanup(null, "interaction");
      301+ return;
      302+ }
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/contextMenuFallback.ts around lines 297-301:
      
      Pressing Escape closes the menu but also reaches `GhosttyTerminalSurface.onKeyDown`, so an interactive terminal command is cancelled. `preventDefault()` does not stop propagation; call `stopPropagation()` before cleanup, as for accelerator actions.
      @@ -197,3 +197,17 @@
      197197 activeContextMenuDismiss = null;
      198198 }
      199199
      200+export function contextMenuAcceleratorAction<T extends string>(
      201+ items: readonly ContextMenuItem<T>[],
      202+ event: Pick<KeyboardEvent, "altKey" | "ctrlKey" | "isComposing" | "key" | "metaKey" | "shiftKey">,
      203+): T | null {
      204+ if (event.isComposing) return null;
      205+
      206+ for (const item of items) {
      207+ if (item.disabled) continue;
      208+ if (item.children) {
      209+ const childAction = contextMenuAcceleratorAction(item.children, event);
      210+ if (childAction !== null) return childAction;
      211+ }
      212+ if (!item.accelerator) continue;
      213+
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium src/contextMenuFallback.ts:206

      When a parent item has children and an accelerator, pressing that accelerator resolves the menu with the parent id, even though the fallback only uses that item to open its submenu. After checking the children, skip the parent accelerator so only a matching leaf action is returned.

         for (const item of items) {
      -    if (item.disabled) continue;
      -    if (item.children) {
      +    if (item.disabled) continue;
      +    if (item.children?.length) {
             const childAction = contextMenuAcceleratorAction(item.children, event);
             if (childAction !== null) return childAction;
      +      continue;
           }
           if (!item.accelerator) continue;
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/contextMenuFallback.ts around lines 206-213:
      
      When a parent item has `children` and an `accelerator`, pressing that accelerator resolves the menu with the parent `id`, even though the fallback only uses that item to open its submenu. After checking the children, skip the parent accelerator so only a matching leaf action is returned.
      @@ -234,9 +283,20 @@
      283+ options?.restoreFocus !== false &&
      284+ (options?.restoreFocus !== "on-dismiss" || reason === "interaction") &&
      285+ shouldRestoreFocus &&
      286+ previouslyFocusedElement?.isConnected
      287+ ) {
      234288 previouslyFocusedElement.focus({ preventScroll: true });
      235289 }
      236290 resolve(result);
      237291 };
      238292
      293+ const onAbort = () => cleanup(null, "programmatic");
      294+
      239295 const onKeyDown = (event: KeyboardEvent) => {
      296+ if (event.isComposing) return;
      240297 if (event.key === "Escape") {
      241298 event.preventDefault();
      242- cleanup(null);
      299+ cleanup(null, "interaction");
      300+ return;
      301+ }
      302+ const action = contextMenuAcceleratorAction(items, event);
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium src/contextMenuFallback.ts:302

      CommandOrControl+C and CmdOrCtrl+C never trigger an action in the fallback menu, so items using Electron’s documented cross-platform accelerator work natively but not in the browser menu. contextMenuAcceleratorAction only recognizes ctrl, alt, command, and cmd, causing both documented tokens to match neither ctrlKey nor metaKey; normalize or reject these accelerator strings before invoking the matcher.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/web/src/contextMenuFallback.ts around line 302:
      
      `CommandOrControl+C` and `CmdOrCtrl+C` never trigger an action in the fallback menu, so items using Electron’s documented cross-platform accelerator work natively but not in the browser menu. `contextMenuAcceleratorAction` only recognizes `ctrl`, `alt`, `command`, and `cmd`, causing both documented tokens to match neither `ctrlKey` nor `metaKey`; normalize or reject these accelerator strings before invoking the matcher.
    4. Reviewed the changed web UI surfaces (apps/web/src/contextMenuFallback.ts, apps/web/src/localApi.ts) against the shared component system and token ownership.

      Good: the new kbd hint reuses the exact MenuShortcut treatment from components/ui/menu.tsx (ms-auto font-medium font-sans text-secondary-label text-xs tracking-widest) and reads the runtime-adjusted --contrast-secondary-label role in the imperative style string, and dropping the inline min-height/font-size overrides makes the default rows finally match the MenuItem geometry (min-h-8 text-base sm:min-h-7 sm:text-sm).

      Two findings on the new accelerator handling, where the fallback diverges from the accelerator grammar it shares with the Electron host and from the app's shared shortcut-label formatting.

      Posted via Macroscope — UI Consistency
      @@ -199,0 +216,21 @@
      216+ event.key.toLowerCase() === parts.at(-1) &&
      217+ event.altKey === parts.includes("alt") &&
      218+ event.ctrlKey === parts.includes("ctrl") &&
      219+ event.metaKey === (parts.includes("command") || parts.includes("cmd")) &&
      220+ event.shiftKey === parts.includes("shift")
      221+ ) {
      222+ return item.id;
      223+ }
      224+ }
      225+
      226+ return null;
      227+}
      228+
      229+function formatContextMenuAccelerator(accelerator: string): string {
      230+ const parts = accelerator.split("+");
      231+ if (!parts.some((part) => part === "Command" || part === "Cmd")) return accelerator;
      232+ const key = parts.at(-1) ?? "";
      233+ return `${parts.includes("Ctrl") ? "⌃" : ""}${parts.includes("Alt") ? "⌥" : ""}${
      234+ parts.includes("Shift") ? "⇧" : ""
      235+ }⌘${key}`;
      236+}
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      The hint notation is chosen by sniffing the accelerator string for Command/Cmd rather than from the platform, so presentation is inconsistent with the rest of the UI: on macOS an item declared "Ctrl+Shift+C" renders the literal text Ctrl+Shift+C, while Kbd/MenuShortcut consumers, the command palette and keybindings settings all render macOS hints as ⌃⇧C via formatShortcutLabel in keybindings.ts. The new test asserting ["Ctrl+Shift+C", "⇧⌘V"] shows two notations mixed inside one popup. The last part is also passed through unnormalized, so "Command+Shift+v" renders ⇧⌘v where the shared formatter would produce ⇧⌘V (and named keys like Escape/ArrowUp stay raw).

      Suggest formatting through the shared keybindings label logic (platform from isMacPlatform(navigator.platform), symbol order ⌃⌥⇧⌘, formatShortcutKeyLabel-style key casing) instead of a local variant, so fallback menu hints match every other shortcut hint in the app.

      Posted via Macroscope — UI Consistency
      @@ -199,0 +201,21 @@
      201+ items: readonly ContextMenuItem<T>[],
      202+ event: Pick<KeyboardEvent, "altKey" | "ctrlKey" | "isComposing" | "key" | "metaKey" | "shiftKey">,
      203+): T | null {
      204+ if (event.isComposing) return null;
      205+
      206+ for (const item of items) {
      207+ if (item.disabled) continue;
      208+ if (item.children) {
      209+ const childAction = contextMenuAcceleratorAction(item.children, event);
      210+ if (childAction !== null) return childAction;
      211+ }
      212+ if (!item.accelerator) continue;
      213+
      214+ const parts = item.accelerator.toLowerCase().split("+");
      215+ if (
      216+ event.key.toLowerCase() === parts.at(-1) &&
      217+ event.altKey === parts.includes("alt") &&
      218+ event.ctrlKey === parts.includes("ctrl") &&
      219+ event.metaKey === (parts.includes("command") || parts.includes("cmd")) &&
      220+ event.shiftKey === parts.includes("shift")
      221+ ) {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      The modifier vocabulary here is narrower than the grammar this same accelerator string is handed to. ElectronMenu.ts now forwards item.accelerator straight to Electron's native menu, whose accelerator tokens include CommandOrControl/CmdOrCtrl, Control, Option and Super. This matcher only understands ctrl, alt, shift, command/cmd, so the canonical cross-platform form ("CmdOrCtrl+Shift+C") can never match in the styled/web host: metaKey === parts.includes("command") and ctrlKey === parts.includes("ctrl") are both false on every platform. The item then shows a shortcut hint that silently does nothing on web, while working on desktop.

      Suggest normalizing modifier tokens once (control→ctrl, option→alt, cmdorctrl/commandorcontrol→meta on macOS else ctrl, super→meta) and sharing that helper with formatContextMenuAccelerator, so both hosts accept the same notation.

      Posted via Macroscope — UI Consistency
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit efd2e945b4c26fbc6d782ecd231c3212f5b5ec10. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -246,13 +310,19 @@
      246310 const onPointerDown = (event: PointerEvent) => {
      247311 if (!canDismissFromPointer || isNodeWithinMenuStack(event.target, menuStack)) {
      248312 return;
      249313 }
      250- cleanup(null);
      314+ cleanup(null, "interaction");
      251315 };
      252316
      253317 const onContextMenu = (event: MouseEvent) => {
      254318 if (!canDismissFromPointer || isNodeWithinMenuStack(event.target, menuStack)) {
      255319 return;
      256320 }
      257321 event.preventDefault();
      258- cleanup(null);
      322+ cleanup(null, "interaction");
      323+ };
      324+
      325+ const onWheel = (event: WheelEvent) => {
      326+ if (!isNodeWithinMenuStack(event.target, menuStack)) {
      327+ cleanup(null, "interaction");
      328+ }

      Wheel dismiss races opening gesture

      Medium Severity

      The new wheel listener closes the fallback menu immediately, without the canDismissFromPointer delay used by pointerdown and contextmenu. Trackpad momentum or a two-finger right-click that also emits a small wheel delta can dismiss the menu in the same frame it opens, including for existing callers that never opted into the new layout or lifecycle options.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit efd2e945b4c26fbc6d782ecd231c3212f5b5ec10. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This is a cross-host context-menu feature that adds browser keyboard interception, focus and cancellation lifecycle management, wheel dismissal, compact/styled presentation, and native accelerator wiring across shared production infrastructure. The breadth of runtime behavior and unresolved shortcut/dismissal concerns make human review appropriate.

      Not approved because:

      • 4 blocking correctness issues found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    7. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

      We are not adding explicit layout and focus options to the web context menu. The existing actions remain available, and these extra preferences are not a priority.

      If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

Sign in to join this conversation.