Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): copy terminal selection instead of a blank clipboard #7678

Mergedsethwebster(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/7678/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

What Changed

Cmd+C / Edit → Copy from the integrated terminal no longer writes a blank clipboard.

The Ghostty canvas has no DOM selection, only a 1×1 empty IME textarea. Native copy and Electron's Edit menu role: "copy" were copying that empty field, then cancelling clipboard.writeText. This change:

  • Parks the Ghostty selection in the hidden textarea and selects it before native/Electron copy run
  • Only preventDefaults and cancels the writeText fallback when clipboardData.setData actually ran
  • Clears the primed textarea on the next non-copy key, composition start, and clearSelection()

Why

#5638 made Ctrl/Cmd+C copy from the canvas terminal, but it treated every native copy event as success — including Electron menu Copy events that have no clipboardData. On macOS that accelerator runs after renderer JS and writes getSelectedText() of the empty textarea, so the OS clipboard ends up blank. Ghostty already formats the selection correctly; copy was throwing the string away.

Fixes #7677 Fixes #6173

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

No UI change — clipboard contents only.


Note

Low Risk Clipboard and hidden-textarea behavior only in the terminal surface; no auth, data, or API changes, with targeted tests covering Electron and IME edge cases.

Overview Fixes Cmd+C / Edit → Copy writing a blank clipboard from the Ghostty canvas terminal, which has no DOM selection—native copy and Electron menu Copy were reading an empty hidden textarea while still canceling the clipboard.writeText fallback.

Adds primeTerminalCopyInput, clearPrimedTerminalCopyInput, and applyTerminalCopyEvent so the formatted selection is written into and selected on the hidden textarea before copy runs, and preventDefault / fallback cancellation only happen when clipboardData.setData succeeds. Copy keydown primes early; onCopyEvent also primes for menu Copy paths that skip keydown. Primed text is cleared on clearSelection, composition start, and ordinary keydowns (via new isTerminalCompositionKey so IME candidates are not wiped).

Adds unit tests in surface.test.ts and a WASM runtimeAbi test that cell-drag selections installed from grid refs format as hello\nworld.

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

Note

Fix blank terminal clipboard by priming hidden textarea with selection

  • Copy via keyboard or menu now writes the current terminal selection into a hidden textarea before the copy event fires, so native copy paths can read it even when clipboardData is absent.
  • applyTerminalCopyEvent only cancels the deferred writeText fallback when the native copy event actually provided clipboardData; otherwise the fallback stays alive to avoid blank clips.
  • IME-related keydowns are detected via isTerminalCompositionKey (isComposing, key === 'Process', keyCode 229) so the copy primer does not wipe in-progress IME candidate text.
  • clearPrimedTerminalCopyInput clears the primed textarea only if its value still matches the primed selection, preserving any IME text that overwrote it.
  • Tests added in surface.test.ts and runtimeAbi.test.ts cover the copy, primer, IME, and selection-format paths.
Macroscope summarized 846fadb.
    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: 2024b8b0-be58-4576-971c-2e68e52df2c2

      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. 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).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bd358ca8a98f513073fe51bd9886b2a9d12084e6. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 846fadb

      Macroscope's review found this PR approvable — Straightforward bug fix for terminal copy producing blank clipboard. Changes are self-contained to copy event handling, well-tested, and all review comments have been addressed in the final commit.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. The IME/CJK HIGH finding was on bd358ca8. Follow-up commits:

      • 7d4f6ebc — do not run the copy-primer clear on composing / Process / 229 keydowns
      • HEAD — clearPrimedTerminalCopyInput only blanks the textarea if it still holds the exact parked copy string, so an IME candidate that replaced it is left alone

      Compositionstart still drops leftover copy text, but only that parked string.

Sign in to join this conversation.