Skip to content
TypeScript

refactor(web): test live Ghostty link resolution directly (#10041)

Julius Marminge6615d3d70ba3
diff --git a/apps/web/src/terminal/ghostty/surface.test.ts b/apps/web/src/terminal/ghostty/surface.test.ts
index e9933cdb4b7..ee3240b41b0 100644
--- a/apps/web/src/terminal/ghostty/surface.test.ts
+++ b/apps/web/src/terminal/ghostty/surface.test.ts
@@ -23,8 +23,6 @@ import {
terminalGridCellAt,
terminalScrollbarGeometry,
terminalScrollbarOffsetAtPointer,
- terminalLinkAtColumn,
- terminalLinkAtPosition,
terminalLinkAtPositionWithRange,
terminalContentOriginY,
terminalFontFamily,
@@ -433,7 +431,7 @@ describe("shouldBlinkTerminalCursor", () => {
});
});
-describe("terminalLinkAtColumn", () => {
+describe("terminalLinkAtPositionWithRange", () => {
it("maps terminal cells to UTF-16 offsets after a wide emoji", () => {
const cells = [
cell("🙂"),
@@ -450,9 +448,11 @@ describe("terminalLinkAtColumn", () => {
wrapsToNext: false,
};
- expect(terminalLinkAtColumn(row, 2)).toBe("https://t3.codes");
- expect(terminalLinkAtColumn(row, cells.length - 1)).toBe("https://t3.codes");
- expect(terminalLinkAtColumn(row, 0)).toBeNull();
+ expect(terminalLinkAtPositionWithRange([row], 0, 2)?.text).toBe("https://t3.codes");
+ expect(terminalLinkAtPositionWithRange([row], 0, cells.length - 1)?.text).toBe(
+ "https://t3.codes",
+ );
+ expect(terminalLinkAtPositionWithRange([row], 0, 0)).toBeNull();
expect(terminalLinkAtPositionWithRange([row], 0, 8)?.range).toEqual({
start: { x: 2, y: 0 },
end: { x: cells.length - 1, y: 0 },
@@ -473,10 +473,10 @@ describe("terminalLinkAtColumn", () => {
row("C:\\repo\\file.ts", false),
];
- expect(terminalLinkAtPosition(rows, 0, 8)).toBe("https://example.com/reference");
- expect(terminalLinkAtPosition(rows, 1, 4)).toBe("https://example.com/reference");
- expect(terminalLinkAtPosition(rows, 2, 2)).toBe("~/project/file");
- expect(terminalLinkAtPosition(rows, 3, 4)).toBe("C:\\repo\\file.ts");
+ expect(terminalLinkAtPositionWithRange(rows, 0, 8)?.text).toBe("https://example.com/reference");
+ expect(terminalLinkAtPositionWithRange(rows, 1, 4)?.text).toBe("https://example.com/reference");
+ expect(terminalLinkAtPositionWithRange(rows, 2, 2)?.text).toBe("~/project/file");
+ expect(terminalLinkAtPositionWithRange(rows, 3, 4)?.text).toBe("C:\\repo\\file.ts");
expect(terminalLinkAtPositionWithRange(rows, 1, 4)).toEqual({
text: "https://example.com/reference",
range: {
@@ -495,13 +495,13 @@ describe("terminalLinkAtColumn", () => {
});
// The head of the wrapped line scrolled above the viewport.
const headCut = [row("ple.com/missing", true), row("head", true)];
- expect(terminalLinkAtPosition(headCut, 0, 4)).toBeNull();
+ expect(terminalLinkAtPositionWithRange(headCut, 0, 4)).toBeNull();
// The bottom row soft-wraps on below the viewport.
const tailCut = [row("https://t3.codes", false, true)];
- expect(terminalLinkAtPosition(tailCut, 0, 8)).toBeNull();
+ expect(terminalLinkAtPositionWithRange(tailCut, 0, 8)).toBeNull();
// A partial bottom row is provably complete and still resolves.
const complete = [row("https://t3.codes", false), row("", false)];
- expect(terminalLinkAtPosition(complete, 0, 8)).toBe("https://t3.codes");
+ expect(terminalLinkAtPositionWithRange(complete, 0, 8)?.text).toBe("https://t3.codes");
// A wide grapheme earlier in the row must not break truncation detection:
// the soft-wrap flag decides, not string-length-versus-cell-count.
const wideFull: GhosttyRow = {
@@ -514,7 +514,7 @@ describe("terminalLinkAtColumn", () => {
isWrapContinuation: false,
wrapsToNext: true,
};
- expect(terminalLinkAtPosition([wideFull], 0, 8)).toBeNull();
+ expect(terminalLinkAtPositionWithRange([wideFull], 0, 8)).toBeNull();
// Unwritten trailing cells prove the bottom row is complete.
const unwrittenTail: GhosttyRow = {
cells: [
@@ -526,7 +526,7 @@ describe("terminalLinkAtColumn", () => {
isWrapContinuation: false,
wrapsToNext: false,
};
- expect(terminalLinkAtPosition([unwrittenTail], 0, 8)).toBe("https://t3.codes");
+ expect(terminalLinkAtPositionWithRange([unwrittenTail], 0, 8)?.text).toBe("https://t3.codes");
});
});
diff --git a/apps/web/src/terminal/ghostty/surface.ts b/apps/web/src/terminal/ghostty/surface.ts
index 826dcd01405..29aaac6f6ab 100644
--- a/apps/web/src/terminal/ghostty/surface.ts
+++ b/apps/web/src/terminal/ghostty/surface.ts
@@ -244,14 +244,6 @@ function terminalColumnOffset(row: GhosttySnapshot["rowData"][number], column: n
return offset;
}
-export function terminalLinkAtPosition(
- rows: GhosttySnapshot["rowData"],
- rowIndex: number,
- column: number,
-): string | null {
- return terminalLinkAtPositionWithRange(rows, rowIndex, column)?.text ?? null;
-}
-
export interface TerminalLinkWithRange {
readonly text: string;
readonly range: GhosttyCellRange;
@@ -325,10 +317,6 @@ export function terminalLinkAtPositionWithRange(
return null;
}
-export function terminalLinkAtColumn(row: GhosttySnapshot["rowData"][number], column: number) {
- return terminalLinkAtPosition([row], 0, column);
-}
-
export function isTerminalCopyShortcut(
event: Pick<KeyboardEvent, "ctrlKey" | "key" | "metaKey" | "shiftKey">,
platform = navigator.platform,