Skip to content

Commit bd358ca

Browse files
committed
fix(web): prime terminal textarea on menu-role copy
Edit-menu Copy never hits the keydown primer, so the native action read a blank or stale IME field. Park the current Ghostty selection in the textarea before the copy event, including when clipboardData is missing.
1 parent 02662f2 commit bd358ca

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎apps/web/src/terminal/ghostty/surface.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,26 @@ describe("applyTerminalCopyEvent", () => {
259259
claimWriteFallback: false,
260260
});
261261
});
262+
263+
it("primes the current selection before a copy event with no clipboardData", () => {
264+
const input = {
265+
value: "stale",
266+
selectionStart: 0,
267+
selectionEnd: 0,
268+
select() {
269+
this.selectionStart = 0;
270+
this.selectionEnd = this.value.length;
271+
},
272+
};
273+
primeTerminalCopyInput(input, "git status");
274+
expect(applyTerminalCopyEvent("git status", null)).toEqual({
275+
preventDefault: false,
276+
claimWriteFallback: false,
277+
});
278+
expect(input.value).toBe("git status");
279+
expect(input.selectionStart).toBe(0);
280+
expect(input.selectionEnd).toBe(10);
281+
});
262282
});
263283

264284
describe("primeTerminalCopyInput", () => {

‎apps/web/src/terminal/ghostty/surface.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,10 @@ export class GhosttyTerminalSurface {
11121112

11131113
private readonly onCopyEvent = (event: ClipboardEvent) => {
11141114
const selection = this.hasSelection() ? this.getSelection() : this.input.value;
1115+
// Menu-role Copy never hits the keydown primer. The native action reads
1116+
// this.input, so park the current selection first — including when
1117+
// clipboardData is missing and we must not preventDefault.
1118+
primeTerminalCopyInput(this.input, selection);
11151119
const result = applyTerminalCopyEvent(selection, event.clipboardData);
11161120
if (result.preventDefault) event.preventDefault();
11171121
if (result.claimWriteFallback) {

0 commit comments

Comments
 (0)