Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): make terminal selection actions reliable #6555

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

What Changed

Terminal text could be selected but then become effectively stuck: Copy was disabled in the desktop fallback menu, Ctrl+Shift+C and Ctrl+Shift+V did nothing while the initial selection popup was open, Paste did not work, and Add to chat disappeared after dismissing the first popup. Scrolling the terminal could leave the popup inconsistent with its selection.

This makes the initial selection popup and the reopened right-click menu use the same terminal-aware actions. Both expose Add to chat, Copy, and Paste; show the platform shortcut (Ctrl+Shift+C/V on Windows and Linux, ⌘C/V on macOS); execute those shortcuts while open; dismiss on outside clicks or terminal scrolling; and can be reopened without losing the selection.

Why

Electron's generic edit menu reads Chromium edit flags, but the terminal renders and owns selection through its canvas-backed Ghostty surface. Those edit flags therefore disabled valid terminal actions and could not paste into the PTY. A shared in-app terminal menu keeps selection, clipboard handling, shortcut behavior, and lifecycle cancellation under the terminal's control while still routing through the local host API.

The menu is aborted when its terminal closes or is replaced, and stale requests cannot act on a removed terminal. Clipboard and chat-context eligibility are tracked separately so newline-only selections remain copyable without creating empty chat context.

UI Changes

Before

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

After

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

Validation

  • 70 focused terminal, context-menu, local API, and desktop-menu tests passed
  • Web, desktop, and contracts typechecks passed
  • Targeted lint, formatting, and git diff --check passed
  • Desktop behavior was exercised by the contributor; automated browser/computer-use verification was not run

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Generated with gpt-5.6-sol in the T3 Code Codex harness.


Note

Medium Risk Changes terminal clipboard/menu lifecycle and extends LocalApi.contextMenu.show; optional contract fields are backward compatible, but styled menus on desktop and abort-driven focus behavior need careful regression testing.

Overview Unifies the post-selection popup and right-click terminal menu so both show the same actions (Add to chat, Copy, Paste), platform shortcuts, and go through a shared runTerminalMenuRequest path with AbortController cancellation, superseded-request guards, and focus restore only after copy/paste.

Context menu platform changes: ContextMenuItem gains optional accelerator, wired into Electron native menus and the web fallback (shortcut labels, contextMenuAcceleratorAction, compact layout). localApi.contextMenu.show accepts presentation: "styled" (forces the DOM menu on desktop), signal, and restoreFocus; close always dismisses the fallback. The fallback also closes on outside scroll and owner abort.

Terminal behavior: Selection eligibility splits canCopy vs canAddToChat (e.g. newline-only selections stay copyable). Ghostty paste() centralizes paste and bumps pasteShortcutToken so menu paste races keyboard clipboard reads; the surface always preventDefault on context menu before the host handles it.

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

Note

Make terminal context menu actions reliable with accelerators, abort support, and focus restoration

  • Adds keyboard accelerators to terminal context menus (copy, paste, add to chat) with platform-specific display (macOS glyphs vs Ctrl+Shift)
  • Introduces runTerminalMenuRequest in ThreadTerminalDrawer.tsx to orchestrate menu open/action/focus with abort signals and stale-request guards; only current requests perform actions or report errors
  • Extends showContextMenuFallback in contextMenuFallback.ts to support AbortSignal, accelerator key activation, outside-scroll dismissal, compact layout, and configurable focus restoration ('on-dismiss')
  • Updates GhosttyTerminalSurface.onContextMenu in surface.ts to always call event.preventDefault() itself; centralizes paste through a new paste() method
  • LocalApi.contextMenu.show now routes to the styled web fallback when presentation: 'styled' is requested, even on desktop; otherwise delegates to native menu
  • Behavioral Change: TerminalViewport no longer calls event.preventDefault() on context menu — the surface now owns this. contextMenu.close always dismisses the styled fallback regardless of desktop bridge presence.
Macroscope summarized 1c7827c.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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: ea62837d-c14d-4f66-af2d-8457c8c95f59

      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

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      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. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR substantially changes terminal menu behavior and shared context-menu lifecycle handling across browser and desktop environments, including new shortcut dispatch, styled menus, cancellation, focus, and clipboard coordination. The cross-cutting runtime impact is broader than a small isolated bug fix and merits human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/3c6c91242d920be2d32d183b4a15bf680f6a93a7/apps/web/src/localApi.ts#L56

      contextMenu.close() is a no-op for styled menus when window.desktopBridge exists, leaving the fallback menu and its pending show() promise open. Because the styled path uses showContextMenuFallback() despite the bridge being available, call dismissContextMenu() regardless of bridge presence.

      ✅ Resolved in 61755c5fee65e58bae280e0427f7c1f455229803

    5. gpt-5.6-sol - responding =====

      Fixed in 61755c5f. contextMenu.close() now always dismisses the DOM fallback, including styled menus opened while the desktop bridge is present. A regression test covers the desktop-bridge close path.

    6. Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    7. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/bd9680a348ab142b1cd7c4162c138690d6a4498e/apps/web/src/components/ThreadTerminalDrawer.tsx#L502

      Right-clicking while the delayed selection-popup timer is pending leaves that timer active, so dismissing the context menu later opens the stale selection popup unexpectedly. This callback bypasses handleContextMenu, which is responsible for clearSelectionAction(); route it through that handler.

      ✅ Resolved in bff9ef4e541d47dcac8f79f4cb5b3a570591972e

    8. UI Consistency — findings

      The imperative fallback menu in apps/web/src/contextMenuFallback.ts has so far mirrored the React menu primitives (MenuPopup, MenuItem, MenuSeparator, MenuGroupLabel) class-for-class. This PR adds a second, hand-tuned menu design inside the same function, keyed implicitly off whether any item has an accelerator, plus a new shortcut chip treatment that doesn't match MenuShortcut/Kbd. Comments inline. One dead handler in ThreadTerminalDrawer.tsx is also flagged.

      Posted via Macroscope — UI Consistency
    9. gpt-5.6-sol - responding =====

      Confirmed and fixed in bff9ef4e. The surface callback now routes through handleContextMenu, which clears the pending selection action and timer before opening the right-click menu. The focused terminal menu tests pass.

    10. Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    11. UI Consistency

      The previous round's findings are addressed: the compact layout is now an explicit layout: "compact" option instead of being inferred from accelerators, the shortcut hint reuses the MenuShortcut class contract, compact rows keep a responsive type step plus opacity-64 for disabled, and handleContextMenu is wired into the surface's onContextMenu.

      Three remaining items on the changed lines:

      1. apps/web/src/contextMenuFallback.ts — the accelerator's imperative style reads var(--secondary-label) instead of the appearance-contrast-adjusted var(--contrast-secondary-label), so the shortcut text splits away from the adjusted colors used everywhere else in this menu.
      2. apps/web/src/contextMenuFallback.ts — inner.dataset.compact has no consumer and emits data-compact="false" on every non-compact menu.
      3. apps/web/src/terminal/ghostty/surface.ts — preventDefault ownership moved from the host into the surface, but the onContextMenu option's doc comment still assigns that ownership to the host.
      Posted via Macroscope — UI Consistency
    12. One finding: the new shortcut <kbd> reads the unadjusted --secondary-label role in its inline style, so it bypasses the contrast bridge that every other imperative color in this file goes through.

      Posted via Macroscope — UI Consistency
    13. One interaction finding on the terminal context menu focus contract; everything flagged in earlier runs (contrast token for the shortcut hint, data-compact, the onContextMenu doc comment, the unused handleContextMenu, MenuShortcut class parity) looks resolved.

      Posted via Macroscope — UI Consistency
    14. 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 475ca8e9ec31cf22e14cee541d853d92aebb0c76. Configure [here](https://www.cursor.com/dashboard/bugbot).
    15. This PR became too broad while covering several independent terminal-menu issues. It has been split into:

      • #8457 for paste race handling
      • #8458 for generic context-menu layout, accelerator, focus, and cancellation options
      • #8459 for terminal-specific menu actions and lifecycle behavior (draft, stacked on #8458)

      Each behavior now has a focused diff and its tests beside it. #8459 will be rebased onto main and marked ready after #8458 lands.

Sign in to join this conversation.