Skip to content

Commit e701daa

Browse files
committed
fix(web): carry selection methods through terminal session sync
1 parent de920d6 commit e701daa

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎apps/web/src/components/ThreadTerminalDrawer.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ it("retains visible output and selection until a replacement subscription receiv
9696
});
9797

9898
it("reports an attach failure that leaves the output unchanged", () => {
99-
const terminal = { resetAndWrite: vi.fn(), write: vi.fn(), clearSelection: vi.fn() };
99+
const terminal = {
100+
resetAndWrite: vi.fn(),
101+
write: vi.fn(),
102+
getSelection: vi.fn(() => "selected"),
103+
getSelectionCellCount: vi.fn(() => 8),
104+
clearSelection: vi.fn(),
105+
};
100106
const previous = { ...EMPTY_TERMINAL_BUFFER_STATE, error: null };
101107
const failed = { ...previous, error: "Terminal attach failed" };
102108

@@ -105,5 +111,7 @@ it("reports an attach failure that leaves the output unchanged", () => {
105111
).toBe(INITIAL_TERMINAL_OUTPUT_CURSOR);
106112
expect(terminal.write).toHaveBeenCalledWith("\r\n[terminal] Terminal attach failed\r\n");
107113
expect(terminal.resetAndWrite).not.toHaveBeenCalled();
114+
expect(terminal.getSelection).not.toHaveBeenCalled();
115+
expect(terminal.getSelectionCellCount).not.toHaveBeenCalled();
108116
expect(terminal.clearSelection).not.toHaveBeenCalled();
109117
});

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export function synchronizeTerminalOutput(
191191

192192
/** Writes what changed between two session notifications: new output, then a new error. */
193193
export function synchronizeTerminalSession(
194-
terminal: Pick<GhosttyTerminalSurface, "resetAndWrite" | "write" | "clearSelection">,
194+
terminal: Parameters<typeof synchronizeTerminalOutput>[0],
195195
previous: Pick<TerminalSessionState, "output" | "version" | "error">,
196196
session: Pick<TerminalSessionState, "output" | "version" | "error">,
197197
cursor: TerminalOutputCursor,

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
INITIAL_TERMINAL_OUTPUT_CURSOR,
55
nextTerminalAttachSeedState,
66
} from "@t3tools/client-runtime/state/terminal";
7-
import { synchronizeTerminalOutput } from "../../components/ThreadTerminalDrawer";
7+
import { synchronizeTerminalSession } from "../../components/ThreadTerminalDrawer";
88

99
import { GhosttyTerminalCore, type GhosttyCell, type GhosttyRow } from "./core";
1010
import {
@@ -445,7 +445,8 @@ describe("GhosttyTerminalSurface visibility", () => {
445445
it("keeps a selection through redraws until the selected text changes", async () => {
446446
const harness = createHarness();
447447
const surface = await harness.create();
448-
let state = applyTerminalAttachStreamEvent(nextTerminalAttachSeedState(), {
448+
const seed = nextTerminalAttachSeedState();
449+
let state = applyTerminalAttachStreamEvent(seed, {
449450
type: "snapshot",
450451
snapshot: {
451452
threadId: "thread",
@@ -461,7 +462,7 @@ describe("GhosttyTerminalSurface visibility", () => {
461462
updatedAt: "2026-10-20T00:00:00.000Z",
462463
},
463464
});
464-
let cursor = synchronizeTerminalOutput(surface, state, INITIAL_TERMINAL_OUTPUT_CURSOR);
465+
let cursor = synchronizeTerminalSession(surface, seed, state, INITIAL_TERMINAL_OUTPUT_CURSOR);
465466
harness.flushFrame();
466467
harness.pointer("pointerdown", 5, 1);
467468
harness.pointer("pointermove", 85, 1);
@@ -470,13 +471,14 @@ describe("GhosttyTerminalSurface visibility", () => {
470471

471472
// A TUI repaints its spinner line in place, the way Claude Code redraws.
472473
const redraw = (data: string) => {
474+
const previous = state;
473475
state = applyTerminalAttachStreamEvent(state, {
474476
type: "output",
475477
threadId: "thread",
476478
terminalId: "term-1",
477479
data,
478480
});
479-
cursor = synchronizeTerminalOutput(surface, state, cursor);
481+
cursor = synchronizeTerminalSession(surface, previous, state, cursor);
480482
};
481483
redraw("\r\x1b[2K* Working |");
482484
expect(surface.getSelection()).toBe("* Working |");

0 commit comments

Comments
 (0)