Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(web): copy terminal selections automatically #9091

Closedjonathanmeier5(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/9091/headopened View on GitHub

Showing 3 changed files with 43 additions and 0 deletions.

x
0 of 3 viewed, 3 left
1 addition and 0 deletionsapps/web/src/components/ThreadTerminalDrawer.tsxModified
View file
@@ -827,6 +827,7 @@
if (!shouldHandle) {
return;
+ terminalRef.current?.copySelectionToClipboard();
Thread on line 830
macroscopeapp[bot](GitHub profile, opens in a new tab)commented

🟡 Medium components/ThreadTerminalDrawer.tsx:830

handleMouseUp overwrites the clipboard with the stale terminal selection after scrollbar gestures and DEC mouse-reporting clicks, even though neither gesture creates or completes a text selection. Because selectionGestureActiveRef is set for every left-button pointerdown in mount, gate this copy on an actual canvas selection gesture (excluding the scrollbar and mouse-reporting path).

Also found in 1 other location(s)

apps/web/src/terminal/ghostty/surface.ts:929

copySelectionToClipboard unconditionally copies whatever selection already exists. The drawer invokes it for every left-button gesture begun in the mount, including a click that onPointerDown routes to an application after DEC mouse tracking is enabled. Since that path does not change/clear a pre-existing Ghostty selection, such application clicks silently overwrite the user's clipboard with stale terminal text rather than only copying a completed selection gesture.

🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/web/src/components/ThreadTerminalDrawer.tsx around line 830:

`handleMouseUp` overwrites the clipboard with the stale terminal selection after scrollbar gestures and DEC mouse-reporting clicks, even though neither gesture creates or completes a text selection. Because `selectionGestureActiveRef` is set for every left-button `pointerdown` in `mount`, gate this copy on an actual canvas selection gesture (excluding the scrollbar and mouse-reporting path).

Also found in 1 other location(s):
- apps/web/src/terminal/ghostty/surface.ts:929 -- `copySelectionToClipboard` unconditionally copies whatever selection already exists. The drawer invokes it for every left-button gesture begun in the mount, including a click that `onPointerDown` routes to an application after DEC mouse tracking is enabled. Since that path does not change/clear a pre-existing Ghostty selection, such application clicks silently overwrite the user's clipboard with stale terminal text rather than only copying a completed selection gesture.
selectionPointerRef.current = { x: event.clientX, y: event.clientY };
const delay = terminalSelectionActionDelayForClickCount(event.detail);
selectionActionTimerRef.current = window.setTimeout(() => {
28 additions and 0 deletionsapps/web/src/terminal/ghostty/surface.test.tsModified
View file
@@ -7,6 +7,7 @@
advanceTerminalSelectionClickSequence,
applyTerminalCopyEvent,
clearPrimedTerminalCopyInput,
+ copyTerminalSelection,
ghosttyMouseButton,
isTerminalAltGraphText,
isTerminalCompositionCommitInput,
@@ -283,6 +284,33 @@
});
});
​
+describe("copyTerminalSelection", () => {
+ it("primes and copies a non-empty terminal selection", () => {
+ const input = {
+ value: "",