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