Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

surface.test.ts

646 lines23.0 KB

1import { describe, expect, it, vi } from "vite-plus/test";
2​
3import type { GhosttyCell, GhosttyRow } from "./core";
4import {
5 DEFAULT_TERMINAL_FONT_FAMILY,
6 DEFAULT_TERMINAL_FONT_SIZE,
7 advanceTerminalSelectionClickSequence,
8 applyTerminalCopyEvent,
9 clearPrimedTerminalCopyInput,
10 ghosttyMouseButton,
11 isTerminalAltGraphText,
12 isTerminalCompositionCommitInput,
13 isTerminalCompositionKey,
14 isTerminalCopyShortcut,
15 isTerminalLinkPointerGesture,
16 isTerminalPasteShortcut,
17 loadTerminalFontFamily,
18 primeTerminalCopyInput,
19 resolveTerminalMouseData,
20 resolveTerminalMouseTrackingState,
21 shouldBlinkTerminalCursor,
22 shouldReportTerminalMouse,
23 shouldShowTerminalLinkHover,
24 terminalGridCellAt,
25 terminalScrollbarGeometry,
26 terminalScrollbarOffsetAtPointer,
27 terminalLinkAtColumn,
28 terminalLinkAtPosition,
29 terminalLinkAtPositionWithRange,
30 terminalContentOriginY,
31 terminalFontFamily,
32 terminalFontSize,
33 terminalWheelArrowData,
34 terminalWheelDeltaRows,
35} from "./surface";
36​
37const cell = (text: string): GhosttyCell => ({
38 text,
39 wide: 0,
40 foreground: { r: 255, g: 255, b: 255 },
41 background: { r: 0, g: 0, b: 0 },
42 bold: false,
43 italic: false,
44 invisible: false,
45 strikethrough: false,
46 overline: false,
47 underline: false,
48 selected: false,
49});
50​
51describe("isTerminalAltGraphText", () => {
52 it("defers printable AltGr output to the textarea input event", () => {
53 expect(
54 isTerminalAltGraphText({
55 key: "@",
56 getModifierState: (modifier) => modifier === "AltGraph",
57 }),
58 ).toBe(true);
59 expect(
60 isTerminalAltGraphText({
61 key: "ArrowRight",
62 getModifierState: (modifier) => modifier === "AltGraph",
63 }),
64 ).toBe(false);
65 });
66});
67​
68describe("terminalGridCellAt", () => {
69 const options = {
70 bounds: { left: 100, top: 200 },
71 cols: 3,
72 rows: 2,
73 metrics: { width: 10, height: 20 },
74 padding: 4,
75 originY: 24,
76 };
77​
78 it("maps points inside the rendered grid without clamping its padding", () => {
79 expect(terminalGridCellAt({ ...options, clientX: 104, clientY: 224 })).toEqual({
80 x: 0,
81 y: 0,
82 });
83 expect(terminalGridCellAt({ ...options, clientX: 133, clientY: 263 })).toEqual({
84 x: 2,
85 y: 1,
86 });
87 expect(terminalGridCellAt({ ...options, clientX: 103, clientY: 224 })).toBeNull();
88 expect(terminalGridCellAt({ ...options, clientX: 104, clientY: 223 })).toBeNull();
89 expect(terminalGridCellAt({ ...options, clientX: 134, clientY: 224 })).toBeNull();
90 expect(terminalGridCellAt({ ...options, clientX: 104, clientY: 264 })).toBeNull();
91 });
92});
93​
94describe("shouldBlinkTerminalCursor", () => {
95 const blinking = {
96 focused: true,
97 cursorBlinking: true,
98 cursorVisible: true,
99 reducedMotion: false,
100 };
101​
102 it("blinks a focused visible cursor the terminal asked to blink", () => {
103 expect(shouldBlinkTerminalCursor(blinking)).toBe(true);
104 });
105​
106 it("holds the cursor steady when blinking would be unwanted", () => {
107 // Unfocused surfaces draw a steady hollow cursor, DECSCUSR steady styles and
108 // DEC mode 12 turn blinking off, a hidden cursor has nothing to toggle, and
109 // reduced-motion readers get no permanently animating element.
110 expect(shouldBlinkTerminalCursor({ ...blinking, focused: false })).toBe(false);
111 expect(shouldBlinkTerminalCursor({ ...blinking, cursorBlinking: false })).toBe(false);
112 expect(shouldBlinkTerminalCursor({ ...blinking, cursorVisible: false })).toBe(false);
113 expect(shouldBlinkTerminalCursor({ ...blinking, reducedMotion: true })).toBe(false);
114 });
115});
116​
117describe("terminalLinkAtColumn", () => {
118 it("maps terminal cells to UTF-16 offsets after a wide emoji", () => {
119 const cells = [
120 cell("πŸ™‚"),
121 cell(""),
122 ...Array.from("https://t3.codes", (character) => cell(character)),
123 ];
124 const row: GhosttyRow = {
125 cells,
126 text: cells
127 .map((value) => value.text || " ")
128 .join("")
129 .trimEnd(),
130 isWrapContinuation: false,
131 wrapsToNext: false,
132 };
133​
134 expect(terminalLinkAtColumn(row, 2)).toBe("https://t3.codes");
135 expect(terminalLinkAtColumn(row, cells.length - 1)).toBe("https://t3.codes");
136 expect(terminalLinkAtColumn(row, 0)).toBeNull();
137 expect(terminalLinkAtPositionWithRange([row], 0, 8)?.range).toEqual({
138 start: { x: 2, y: 0 },
139 end: { x: cells.length - 1, y: 0 },
140 });
141 });
142​
143 it("uses shared path matching and reconstructs soft-wrapped links", () => {
144 const row = (text: string, isWrapContinuation: boolean, wrapsToNext = false): GhosttyRow => ({
145 cells: Array.from(text.padEnd(16), (character) => cell(character)),
146 text: text.trimEnd(),
147 isWrapContinuation,
148 wrapsToNext,
149 });
150 const rows = [
151 row("https://example.", false),
152 row("com/reference", true),
153 row("~/project/file", false),
154 row("C:\\repo\\file.ts", false),
155 ];
156​
157 expect(terminalLinkAtPosition(rows, 0, 8)).toBe("https://example.com/reference");
158 expect(terminalLinkAtPosition(rows, 1, 4)).toBe("https://example.com/reference");
159 expect(terminalLinkAtPosition(rows, 2, 2)).toBe("~/project/file");
160 expect(terminalLinkAtPosition(rows, 3, 4)).toBe("C:\\repo\\file.ts");
161 expect(terminalLinkAtPositionWithRange(rows, 1, 4)).toEqual({
162 text: "https://example.com/reference",
163 range: {
164 start: { x: 0, y: 0 },
165 end: { x: 12, y: 1 },
166 },
167 });
168 });
169​
170 it("refuses links truncated at the viewport edges instead of mis-resolving", () => {
171 const row = (text: string, isWrapContinuation: boolean, wrapsToNext = false): GhosttyRow => ({
172 cells: Array.from(text.padEnd(16), (character) => cell(character)),
173 text: text.trimEnd(),
174 isWrapContinuation,
175 wrapsToNext,
176 });
177 // The head of the wrapped line scrolled above the viewport.
178 const headCut = [row("ple.com/missing", true), row("head", true)];
179 expect(terminalLinkAtPosition(headCut, 0, 4)).toBeNull();
180 // The bottom row soft-wraps on below the viewport.
181 const tailCut = [row("https://t3.codes", false, true)];
182 expect(terminalLinkAtPosition(tailCut, 0, 8)).toBeNull();
183 // A partial bottom row is provably complete and still resolves.
184 const complete = [row("https://t3.codes", false), row("", false)];
185 expect(terminalLinkAtPosition(complete, 0, 8)).toBe("https://t3.codes");
186 // A wide grapheme earlier in the row must not break truncation detection:
187 // the soft-wrap flag decides, not string-length-versus-cell-count.
188 const wideFull: GhosttyRow = {
189 cells: [
190 { ...cell("πŸ™‚"), wide: 1 },
191 { ...cell(""), wide: 2 },
192 ...Array.from("https://t3.code", (character) => cell(character)),
193 ],
194 text: "πŸ™‚ https://t3.code",
195 isWrapContinuation: false,
196 wrapsToNext: true,
197 };
198 expect(terminalLinkAtPosition([wideFull], 0, 8)).toBeNull();
199 // Unwritten trailing cells prove the bottom row is complete.
200 const unwrittenTail: GhosttyRow = {
201 cells: [
202 ...Array.from("https://t3.codes", (character) => cell(character)),
203 cell(""),
204 cell(""),
205 ],
206 text: "https://t3.codes",
207 isWrapContinuation: false,
208 wrapsToNext: false,
209 };
210 expect(terminalLinkAtPosition([unwrittenTail], 0, 8)).toBe("https://t3.codes");
211 });
212});
213​
214describe("isTerminalCopyShortcut", () => {
215 const event = (overrides: Partial<Parameters<typeof isTerminalCopyShortcut>[0]> = {}) => ({
216 ctrlKey: false,
217 key: "c",
218 metaKey: false,
219 shiftKey: false,
220 ...overrides,
221 });
222​
223 it("keeps Ctrl+C available for SIGINT on macOS", () => {
224 expect(isTerminalCopyShortcut(event({ ctrlKey: true }), "MacIntel")).toBe(false);
225 expect(isTerminalCopyShortcut(event({ metaKey: true }), "MacIntel")).toBe(true);
226 });
227​
228 it("copies with Ctrl+C and Ctrl+Shift+C elsewhere", () => {
229 expect(isTerminalCopyShortcut(event({ ctrlKey: true }), "Linux x86_64")).toBe(true);
230 expect(isTerminalCopyShortcut(event({ ctrlKey: true, shiftKey: true }), "Linux x86_64")).toBe(
231 true,
232 );
233 expect(isTerminalCopyShortcut(event({}), "Linux x86_64")).toBe(false);
234 });
235​
236 it("uses the produced character instead of the physical key position", () => {
237 expect(isTerminalCopyShortcut(event({ key: "C", metaKey: true }), "MacIntel")).toBe(true);
238 expect(isTerminalCopyShortcut(event({ key: "j", metaKey: true }), "MacIntel")).toBe(false);
239 });
240});
241​
242describe("applyTerminalCopyEvent", () => {
243 it("writes the selection and claims the fallback when clipboardData is present", () => {
244 const setData = vi.fn();
245 expect(applyTerminalCopyEvent("ls -la", { setData })).toEqual({
246 preventDefault: true,
247 claimWriteFallback: true,
248 });
249 expect(setData).toHaveBeenCalledWith("text/plain", "ls -la");
250 });
251​
252 it("leaves the writeText fallback alive when clipboardData is missing", () => {
253 // Electron's edit-menu Copy often delivers a copy event with no
254 // clipboardData. Claiming that event used to skip writeText and copy the
255 // empty IME textarea, which is the blank clipboard users paste.
256 expect(applyTerminalCopyEvent("ls -la", null)).toEqual({
257 preventDefault: false,
258 claimWriteFallback: false,
259 });
260 expect(applyTerminalCopyEvent("", { setData: vi.fn() })).toEqual({
261 preventDefault: false,
262 claimWriteFallback: false,
263 });
264 });
265​
266 it("primes the current selection before a copy event with no clipboardData", () => {
267 const input = {
268 value: "stale",
269 selectionStart: 0,
270 selectionEnd: 0,
271 select() {
272 this.selectionStart = 0;
273 this.selectionEnd = this.value.length;
274 },
275 };
276 primeTerminalCopyInput(input, "git status");
277 expect(applyTerminalCopyEvent("git status", null)).toEqual({
278 preventDefault: false,
279 claimWriteFallback: false,
280 });
281 expect(input.value).toBe("git status");
282 expect(input.selectionStart).toBe(0);
283 expect(input.selectionEnd).toBe(10);
284 });
285});
286​
287describe("primeTerminalCopyInput", () => {
288 it("selects the Ghostty selection in the hidden textarea so native copy has text", () => {
289 const input = {
290 value: "",
291 selectionStart: 0,
292 selectionEnd: 0,
293 select() {
294 this.selectionStart = 0;
295 this.selectionEnd = this.value.length;
296 },
297 };
298 primeTerminalCopyInput(input, "git status");
299 expect(input.value).toBe("git status");
300 expect(input.selectionStart).toBe(0);
301 expect(input.selectionEnd).toBe(10);
302 clearPrimedTerminalCopyInput(input, "git status");
303 expect(input.value).toBe("");
304 });
305​
306 it("does not wipe an IME candidate that replaced the primed copy", () => {
307 const input = { value: "", select() {} };
308 primeTerminalCopyInput(input, "git status");
309 input.value = "あ";
310 clearPrimedTerminalCopyInput(input, "git status");
311 expect(input.value).toBe("あ");
312 });
313});
314​
315describe("isTerminalPasteShortcut", () => {
316 const event = (overrides: Partial<Parameters<typeof isTerminalPasteShortcut>[0]> = {}) => ({
317 ctrlKey: false,
318 key: "v",
319 metaKey: false,
320 shiftKey: false,
321 ...overrides,
322 });
323​
324 it("uses Cmd+V on macOS", () => {
325 expect(isTerminalPasteShortcut(event({ metaKey: true }), "MacIntel")).toBe(true);
326 expect(isTerminalPasteShortcut(event({ ctrlKey: true }), "MacIntel")).toBe(false);
327 });
328​
329 it("preserves Ctrl+V and uses Ctrl+Shift+V elsewhere", () => {
330 expect(isTerminalPasteShortcut(event({ ctrlKey: true }), "Linux x86_64")).toBe(false);
331 expect(isTerminalPasteShortcut(event({ ctrlKey: true, shiftKey: true }), "Linux x86_64")).toBe(
332 true,
333 );
334 });
335​
336 it("supports the conventional Shift+Insert paste shortcut", () => {
337 expect(isTerminalPasteShortcut(event({ key: "Insert", shiftKey: true }), "Linux x86_64")).toBe(
338 true,
339 );
340 expect(isTerminalPasteShortcut(event({ key: "Insert" }), "Linux x86_64")).toBe(false);
341 expect(
342 isTerminalPasteShortcut(
343 event({ key: "Insert", ctrlKey: true, shiftKey: true }),
344 "Linux x86_64",
345 ),
346 ).toBe(false);
347 expect(isTerminalPasteShortcut(event({ key: "Insert", shiftKey: true }), "MacIntel")).toBe(
348 false,
349 );
350 });
351});
352​
353describe("isTerminalCompositionCommitInput", () => {
354 it("identifies browser composition follow-up input", () => {
355 expect(isTerminalCompositionCommitInput({ inputType: "" })).toBe(true);
356 expect(isTerminalCompositionCommitInput({ inputType: "insertCompositionText" })).toBe(true);
357 expect(isTerminalCompositionCommitInput({ inputType: "insertFromComposition" })).toBe(true);
358 });
359​
360 it("keeps a fast repeated input as legitimate text", () => {
361 expect(isTerminalCompositionCommitInput({ inputType: "insertText" })).toBe(false);
362 });
363});
364​
365describe("isTerminalCompositionKey", () => {
366 const event = (
367 overrides: Partial<Pick<KeyboardEvent, "isComposing" | "key" | "keyCode">> = {},
368 ) => ({
369 isComposing: false,
370 key: "a",
371 keyCode: 65,
372 ...overrides,
373 });
374​
375 it("treats in-progress IME keydowns as composition so the copy primer cannot wipe them", () => {
376 expect(isTerminalCompositionKey(event({ isComposing: true }), false)).toBe(true);
377 expect(isTerminalCompositionKey(event(), true)).toBe(true);
378 expect(isTerminalCompositionKey(event({ key: "Process" }), false)).toBe(true);
379 expect(isTerminalCompositionKey(event({ keyCode: 229 }), false)).toBe(true);
380 });
381​
382 it("lets ordinary keydowns clear a primed copy", () => {
383 expect(isTerminalCompositionKey(event(), false)).toBe(false);
384 });
385});
386​
387describe("application mouse reporting", () => {
388 const event = (overrides: Partial<Parameters<typeof shouldReportTerminalMouse>[1]> = {}) => ({
389 ctrlKey: false,
390 metaKey: false,
391 shiftKey: false,
392 ...overrides,
393 });
394​
395 it("keeps Shift and link activation modifiers available to the browser", () => {
396 expect(shouldReportTerminalMouse(true, event())).toBe(true);
397 expect(shouldReportTerminalMouse(true, event({ shiftKey: true }))).toBe(false);
398 expect(shouldReportTerminalMouse(true, event({ ctrlKey: true }))).toBe(false);
399 expect(shouldReportTerminalMouse(true, event({ metaKey: true }))).toBe(false);
400 expect(shouldReportTerminalMouse(false, event())).toBe(false);
401 });
402​
403 it("maps browser buttons to Ghostty's button enum", () => {
404 expect([0, 1, 2, 3, 4, 5].map(ghosttyMouseButton)).toEqual([1, 3, 2, 4, 5, null]);
405 });
406​
407 it("drops repeated motion reports until another mouse action resets the cell", () => {
408 const first = resolveTerminalMouseData("motion", "\u001b[<35;8;4M", "");
409 expect(first).toEqual({ send: true, nextMotionData: "\u001b[<35;8;4M" });
410​
411 const duplicate = resolveTerminalMouseData("motion", "\u001b[<35;8;4M", first.nextMotionData);
412 expect(duplicate).toEqual({ send: false, nextMotionData: "\u001b[<35;8;4M" });
413​
414 const press = resolveTerminalMouseData("press", "\u001b[<0;8;4M", duplicate.nextMotionData);
415 expect(press).toEqual({ send: true, nextMotionData: "" });
416​
417 expect(resolveTerminalMouseData("motion", "\u001b[<35;8;4M", press.nextMotionData)).toEqual({
418 send: true,
419 nextMotionData: "\u001b[<35;8;4M",
420 });
421 });
422​
423 it("clears the motion baseline when application mouse tracking changes", () => {
424 expect(resolveTerminalMouseTrackingState(true, false, "\u001b[<35;8;4M")).toEqual({
425 tracking: false,
426 motionData: "",
427 });
428 expect(resolveTerminalMouseTrackingState(false, true, "\u001b[<35;8;4M")).toEqual({
429 tracking: true,
430 motionData: "",
431 });
432 expect(resolveTerminalMouseTrackingState(true, true, "\u001b[<35;8;4M")).toEqual({
433 tracking: true,
434 motionData: "\u001b[<35;8;4M",
435 });
436 expect(resolveTerminalMouseTrackingState(false, false, "\u001b[<35;8;4M")).toEqual({
437 tracking: false,
438 motionData: "\u001b[<35;8;4M",
439 });
440 });
441​
442 it("only shows link hover during mouse tracking when the link modifier is held", () => {
443 expect(shouldShowTerminalLinkHover(false, false)).toBe(true);
444 expect(shouldShowTerminalLinkHover(false, true)).toBe(true);
445 expect(shouldShowTerminalLinkHover(true, false)).toBe(false);
446 expect(shouldShowTerminalLinkHover(true, true)).toBe(true);
447 });
448});
449​
450describe("terminal font resolution", () => {
451 it("validates the requested face after its styles load", async () => {
452 let loaded = false;
453 const load = vi.fn(async () => {
454 loaded = true;
455 return [];
456 });
457 const resolve = vi.fn(() => {
458 expect(loaded).toBe(true);
459 return DEFAULT_TERMINAL_FONT_FAMILY;
460 });
461​
462 await expect(
463 loadTerminalFontFamily("Proportional Test", 12, {
464 load,
465 resolve,
466 }),
467 ).resolves.toBe(DEFAULT_TERMINAL_FONT_FAMILY);
468 expect(load).toHaveBeenCalledTimes(4);
469 expect(resolve).toHaveBeenCalledWith("Proportional Test");
470 });
471​
472 it("keeps the glyph fallbacks behind a custom text face", () => {
473 expect(terminalFontFamily()).toBe(DEFAULT_TERMINAL_FONT_FAMILY);
474 expect(terminalFontFamily(" ")).toBe(DEFAULT_TERMINAL_FONT_FAMILY);
475 const custom = terminalFontFamily('"Fira Code"');
476 expect(custom.startsWith('"Fira Code", ')).toBe(true);
477 expect(custom).toContain('"Symbols Nerd Font Mono"');
478 expect(custom.endsWith("monospace")).toBe(true);
479 });
480​
481 it("ignores proportional families the cell grid cannot lay out", () => {
482 // jsdom has no canvas metrics, so the probe answers "monospace" and the
483 // family is kept; the guard is exercised in the browser instead. Assert the
484 // shape stays intact so a rejected face still yields a usable stack.
485 const stack = terminalFontFamily("Helvetica Neue");
486 expect(stack.endsWith("monospace")).toBe(true);
487 });
488​
489 it("quotes families the canvas font shorthand would otherwise reject", () => {
490 expect(terminalFontFamily("3270 Nerd Font").startsWith('"3270 Nerd Font", ')).toBe(true);
491 expect(terminalFontFamily("M+ 1m").startsWith('"M+ 1m", ')).toBe(true);
492 expect(terminalFontFamily("Cascadia Code, Menlo").startsWith('"Cascadia Code", Menlo, ')).toBe(
493 true,
494 );
495 expect(terminalFontFamily(" , ")).toBe(DEFAULT_TERMINAL_FONT_FAMILY);
496 });
497​
498 it("clamps requested font sizes to the supported range", () => {
499 expect(terminalFontSize()).toBe(DEFAULT_TERMINAL_FONT_SIZE);
500 expect(terminalFontSize(Number.NaN)).toBe(DEFAULT_TERMINAL_FONT_SIZE);
501 expect(terminalFontSize(13.4)).toBe(13);
502 expect(terminalFontSize(2)).toBe(6);
503 expect(terminalFontSize(90)).toBe(32);
504 });
505});
506​
507describe("terminalContentOriginY", () => {
508 it("stays top-anchored like a fresh terminal until scrollback exists", () => {
509 expect(terminalContentOriginY(100, 4, 5, 16, false)).toBe(4);
510 });
511​
512 it("pins the grid to the bottom by moving the sub-row slack above row 0", () => {
513 // 100px mount, 4px padding, 5 rows of 16px: 92 - 80 = 12px slack on top.
514 expect(terminalContentOriginY(100, 4, 5, 16, true)).toBe(16);
515 // Exact fit keeps the origin at the padding.
516 expect(terminalContentOriginY(88, 4, 5, 16, true)).toBe(4);
517 // A mount smaller than the grid never pushes the origin above the padding.
518 expect(terminalContentOriginY(80, 4, 5, 16, true)).toBe(4);
519 });
520​
521 it("keeps the prompt stationary while a drag crosses row boundaries", () => {
522 // Growing the mount pixel by pixel: the bottom edge (origin + rows*cell)
523 // tracks the mount bottom exactly until a new row fits.
524 for (let height = 88; height < 104; height += 1) {
525 const rows = Math.max(1, Math.floor((height - 8) / 16));
526 const origin = terminalContentOriginY(height, 4, rows, 16, true);
527 expect(origin + rows * 16).toBe(height - 4);
528 }
529 });
530});
531​
532describe("terminalWheelDeltaRows", () => {
533 it("converts line-mode deltas into whole rows", () => {
534 const result = terminalWheelDeltaRows({ deltaY: 3, deltaMode: 1 }, 16, 24, 0);
535 expect(result.rows).toBe(3);
536 expect(result.remainder).toBe(0);
537 });
538​
539 it("accumulates fractional pixel deltas across events", () => {
540 let remainder = 0;
541 let scrolled = 0;
542 for (let index = 0; index < 4; index += 1) {
543 const result = terminalWheelDeltaRows({ deltaY: 5, deltaMode: 0 }, 16, 24, remainder);
544 remainder = result.remainder;
545 scrolled += result.rows;
546 }
547 expect(scrolled).toBe(1);
548 expect(remainder).toBeCloseTo(4 / 16);
549 });
550​
551 it("keeps direction for negative page-mode deltas", () => {
552 const result = terminalWheelDeltaRows({ deltaY: -1, deltaMode: 2 }, 16, 24, 0);
553 expect(result.rows).toBe(-24);
554 expect(result.remainder).toBe(0);
555 });
556});
557​
558describe("terminalWheelArrowData", () => {
559 it("emits one arrow per row honoring application cursor keys", () => {
560 expect(terminalWheelArrowData(-2, false)).toBe("\u001b[A\u001b[A");
561 expect(terminalWheelArrowData(3, false)).toBe("\u001b[B\u001b[B\u001b[B");
562 expect(terminalWheelArrowData(-1, true)).toBe("\u001bOA");
563 expect(terminalWheelArrowData(0, true)).toBe("");
564 });
565});
566​
567describe("isTerminalLinkPointerGesture", () => {
568 it("uses Command on macOS and Control elsewhere", () => {
569 expect(isTerminalLinkPointerGesture({ ctrlKey: false, metaKey: true }, "MacIntel")).toBe(true);
570 expect(isTerminalLinkPointerGesture({ ctrlKey: true, metaKey: false }, "MacIntel")).toBe(false);
571 expect(isTerminalLinkPointerGesture({ ctrlKey: true, metaKey: false }, "Linux x86_64")).toBe(
572 true,
573 );
574 expect(isTerminalLinkPointerGesture({ ctrlKey: false, metaKey: true }, "Linux x86_64")).toBe(
575 false,
576 );
577 });
578});
579​
580describe("advanceTerminalSelectionClickSequence", () => {
581 it("recognizes stationary double and triple pointer presses without PointerEvent.detail", () => {
582 const first = advanceTerminalSelectionClickSequence(null, {
583 clientX: 20,
584 clientY: 30,
585 timeStamp: 1_000,
586 });
587 const second = advanceTerminalSelectionClickSequence(first, {
588 clientX: 22,
589 clientY: 29,
590 timeStamp: 1_200,
591 });
592 const third = advanceTerminalSelectionClickSequence(second, {
593 clientX: 21,
594 clientY: 31,
595 timeStamp: 1_400,
596 });
597​
598 expect([first.count, second.count, third.count]).toEqual([1, 2, 3]);
599 });
600​
601 it("starts over after movement, delay, or a completed triple click", () => {
602 const previous = { count: 3, time: 1_000, x: 20, y: 30 };
603 expect(
604 advanceTerminalSelectionClickSequence(previous, {
605 clientX: 20,
606 clientY: 30,
607 timeStamp: 1_100,
608 }).count,
609 ).toBe(1);
610 expect(
611 advanceTerminalSelectionClickSequence(previous, {
612 clientX: 30,
613 clientY: 30,
614 timeStamp: 1_100,
615 }).count,
616 ).toBe(1);
617 expect(
618 advanceTerminalSelectionClickSequence(previous, {
619 clientX: 20,
620 clientY: 30,
621 timeStamp: 1_501,
622 }).count,
623 ).toBe(1);
624 });
625});
626​
627describe("terminal scrollbar", () => {
628 it("maps Ghostty's viewport state to a proportional thumb", () => {
629 expect(terminalScrollbarGeometry({ total: 100, offset: 40, len: 20 }, 200)).toEqual({
630 thumbHeight: 40,
631 thumbTop: 80,
632 maxOffset: 80,
633 });
634 expect(terminalScrollbarGeometry({ total: 100, offset: 0, len: 100 }, 200)).toBeNull();
635 });
636​
637 it("keeps the thumb usable for large scrollback and maps dragging back to rows", () => {
638 const state = { total: 10_000, offset: 0, len: 20 };
639 expect(terminalScrollbarGeometry(state, 200)).toEqual({
640 thumbHeight: 18,
641 thumbTop: 0,
642 maxOffset: 9_980,
643 });
644 expect(terminalScrollbarOffsetAtPointer(state, 200, 191, 9)).toBe(9_980);
645 });
646});