Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 9d9a872

Browse files
authored
fix(web): restore terminal link hover styles (pingdotgg#5382)
1 parent 9235c83 commit 9d9a872

4 files changed

Lines changed: 309 additions & 12 deletions

File tree

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,62 @@ describe("ghosttyTextRunEnd", () => {
7171
});
7272

7373
describe("renderGhosttySnapshot", () => {
74+
it("underlines every cell in a hovered wrapped link", () => {
75+
const fillRectCalls: number[][] = [];
76+
const context = {
77+
canvas: { width: 200, height: 80 },
78+
beginPath: () => {},
79+
clip: () => {},
80+
fillRect: (...args: number[]) => fillRectCalls.push(args),
81+
fillText: () => {},
82+
rect: () => {},
83+
resetTransform: () => {},
84+
restore: () => {},
85+
save: () => {},
86+
set fillStyle(_value: string) {},
87+
set font(_value: string) {},
88+
set textBaseline(_value: string) {},
89+
} as unknown as CanvasRenderingContext2D;
90+
const snapshot: GhosttySnapshot = {
91+
cols: 4,
92+
rows: 2,
93+
foreground: { r: 255, g: 255, b: 255 },
94+
background: { r: 0, g: 0, b: 0 },
95+
cursor: { r: 255, g: 255, b: 255 },
96+
cursorX: -1,
97+
cursorY: -1,
98+
cursorVisible: false,
99+
cursorBlinking: false,
100+
cursorStyle: 1,
101+
dirtyRows: new Set([0, 1]),
102+
rowData: [0, 1].map(() => ({
103+
cells: [cell("a"), cell("b"), cell("c"), cell("d")],
104+
text: "abcd",
105+
isWrapContinuation: false,
106+
wrapsToNext: false,
107+
})),
108+
};
109+
110+
renderGhosttySnapshot({
111+
context,
112+
snapshot,
113+
metrics: { width: 10, height: 20, baseline: 15 },
114+
fontSize: 12,
115+
fontFamily: "monospace",
116+
padding: 4,
117+
forceFull: false,
118+
cursorOn: false,
119+
hoveredLinkRange: { start: { x: 2, y: 0 }, end: { x: 1, y: 1 } },
120+
});
121+
122+
expect(fillRectCalls.filter(([, , , height]) => height === 1)).toEqual([
123+
[24, 22, 10, 1],
124+
[34, 22, 10, 1],
125+
[4, 42, 10, 1],
126+
[14, 42, 10, 1],
127+
]);
128+
});
129+
74130
it("constrains text runs and cursor glyphs to their terminal cells", () => {
75131
const fillTextCalls: unknown[][] = [];
76132
const context = {

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export interface GhosttyCellMetrics {
1212
readonly baseline: number;
1313
}
1414

15+
export interface GhosttyCellRange {
16+
readonly start: { readonly x: number; readonly y: number };
17+
readonly end: { readonly x: number; readonly y: number };
18+
}
19+
1520
const DEFAULT_SELECTION_BACKGROUND = "rgba(72, 122, 191, 0.35)";
1621

1722
function cssColor(color: GhosttyColor): string {
@@ -98,6 +103,7 @@ export function renderGhosttySnapshot(options: {
98103
readonly previousCursorY?: number | null;
99104
readonly focused?: boolean;
100105
readonly selectionBackground?: string;
106+
readonly hoveredLinkRange?: GhosttyCellRange | null;
101107
/** Vertical origin of row 0; defaults to the horizontal padding. */
102108
readonly originY?: number;
103109
}): void {
@@ -114,6 +120,7 @@ export function renderGhosttySnapshot(options: {
114120
} = options;
115121
const focused = options.focused ?? true;
116122
const selectionBackground = options.selectionBackground ?? DEFAULT_SELECTION_BACKGROUND;
123+
const hoveredLinkRange = options.hoveredLinkRange ?? null;
117124
const originY = options.originY ?? padding;
118125
const rowsToDraw = forceFull
119126
? Array.from({ length: snapshot.rows }, (_, index) => index)
@@ -216,10 +223,20 @@ export function renderGhosttySnapshot(options: {
216223

217224
for (let column = 0; column < row.cells.length; column += 1) {
218225
const cell = row.cells[column];
219-
if (!cell || (!cell.underline && !cell.strikethrough && !cell.overline)) continue;
226+
const hoveredLink =
227+
hoveredLinkRange !== null &&
228+
rowIndex >= hoveredLinkRange.start.y &&
229+
rowIndex <= hoveredLinkRange.end.y &&
230+
(rowIndex > hoveredLinkRange.start.y || column >= hoveredLinkRange.start.x) &&
231+
(rowIndex < hoveredLinkRange.end.y || column <= hoveredLinkRange.end.x);
232+
if (!cell || (!cell.underline && !cell.strikethrough && !cell.overline && !hoveredLink)) {
233+
continue;
234+
}
220235
context.fillStyle = cssColor(cell.foreground);
221236
const left = padding + column * metrics.width;
222-
if (cell.underline) context.fillRect(left, top + metrics.height - 2, metrics.width, 1);
237+
if (cell.underline || hoveredLink) {
238+
context.fillRect(left, top + metrics.height - 2, metrics.width, 1);
239+
}
223240
if (cell.strikethrough) {
224241
context.fillRect(left, top + Math.floor(metrics.height * 0.55), metrics.width, 1);
225242
}

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import {
1313
isTerminalPasteShortcut,
1414
shouldBlinkTerminalCursor,
1515
shouldReportTerminalMouse,
16+
shouldShowTerminalLinkHover,
17+
terminalGridCellAt,
1618
terminalScrollbarGeometry,
1719
terminalScrollbarOffsetAtPointer,
1820
terminalLinkAtColumn,
1921
terminalLinkAtPosition,
22+
terminalLinkAtPositionWithRange,
2023
terminalContentOriginY,
2124
terminalFontFamily,
2225
fittedTerminalFontSize,
@@ -56,6 +59,32 @@ describe("isTerminalAltGraphText", () => {
5659
});
5760
});
5861

62+
describe("terminalGridCellAt", () => {
63+
const options = {
64+
bounds: { left: 100, top: 200 },
65+
cols: 3,
66+
rows: 2,
67+
metrics: { width: 10, height: 20 },
68+
padding: 4,
69+
originY: 24,
70+
};
71+
72+
it("maps points inside the rendered grid without clamping its padding", () => {
73+
expect(terminalGridCellAt({ ...options, clientX: 104, clientY: 224 })).toEqual({
74+
x: 0,
75+
y: 0,
76+
});
77+
expect(terminalGridCellAt({ ...options, clientX: 133, clientY: 263 })).toEqual({
78+
x: 2,
79+
y: 1,
80+
});
81+
expect(terminalGridCellAt({ ...options, clientX: 103, clientY: 224 })).toBeNull();
82+
expect(terminalGridCellAt({ ...options, clientX: 104, clientY: 223 })).toBeNull();
83+
expect(terminalGridCellAt({ ...options, clientX: 134, clientY: 224 })).toBeNull();
84+
expect(terminalGridCellAt({ ...options, clientX: 104, clientY: 264 })).toBeNull();
85+
});
86+
});
87+
5988
describe("shouldBlinkTerminalCursor", () => {
6089
const blinking = {
6190
focused: true,
@@ -99,6 +128,10 @@ describe("terminalLinkAtColumn", () => {
99128
expect(terminalLinkAtColumn(row, 2)).toBe("https://t3.codes");
100129
expect(terminalLinkAtColumn(row, cells.length - 1)).toBe("https://t3.codes");
101130
expect(terminalLinkAtColumn(row, 0)).toBeNull();
131+
expect(terminalLinkAtPositionWithRange([row], 0, 8)?.range).toEqual({
132+
start: { x: 2, y: 0 },
133+
end: { x: cells.length - 1, y: 0 },
134+
});
102135
});
103136

104137
it("uses shared path matching and reconstructs soft-wrapped links", () => {
@@ -119,6 +152,13 @@ describe("terminalLinkAtColumn", () => {
119152
expect(terminalLinkAtPosition(rows, 1, 4)).toBe("https://example.com/reference");
120153
expect(terminalLinkAtPosition(rows, 2, 2)).toBe("~/project/file");
121154
expect(terminalLinkAtPosition(rows, 3, 4)).toBe("C:\\repo\\file.ts");
155+
expect(terminalLinkAtPositionWithRange(rows, 1, 4)).toEqual({
156+
text: "https://example.com/reference",
157+
range: {
158+
start: { x: 0, y: 0 },
159+
end: { x: 12, y: 1 },
160+
},
161+
});
122162
});
123163

124164
it("refuses links truncated at the viewport edges instead of mis-resolving", () => {
@@ -245,6 +285,13 @@ describe("application mouse reporting", () => {
245285
it("maps browser buttons to Ghostty's button enum", () => {
246286
expect([0, 1, 2, 3, 4, 5].map(ghosttyMouseButton)).toEqual([1, 3, 2, 4, 5, null]);
247287
});
288+
289+
it("only shows link hover during mouse tracking when the link modifier is held", () => {
290+
expect(shouldShowTerminalLinkHover(false, false)).toBe(true);
291+
expect(shouldShowTerminalLinkHover(false, true)).toBe(true);
292+
expect(shouldShowTerminalLinkHover(true, false)).toBe(false);
293+
expect(shouldShowTerminalLinkHover(true, true)).toBe(true);
294+
});
248295
});
249296

250297
describe("terminal font resolution", () => {

0 commit comments

Comments
 (0)