A local-first multi-agent app development platform, built on PenguinHarness
fix(web): render links in a terminal (#556)
Myriad-Dreamin60460a46d552
diff --git a/changelog/unreleased/2026-08-30-terminal-links.md b/changelog/unreleased/2026-08-30-terminal-links.mdnew file mode 100644index 00000000..42013d68--- /dev/null+++ b/changelog/unreleased/2026-08-30-terminal-links.md@@ -0,0 +1,25 @@+# Links in a terminal open where they point++- **Date:** 2026-08-30+- **Type:** fix+- **Scope:** `web`+- **PR:** [#556](https://github.com/Prism-Shadow/penguin-harness/pull/556)++[中文版](2026-08-30-terminal-links.zh.md)++Clicking a URL in a terminal opened `about:blank` instead of the address, and a hyperlink written by a program — the way `gh` and the agent CLIs print a pull request — first asked "Do you want to navigate to …? WARNING: This link could potentially be dangerous" and then did nothing either way.++## Details++- Both paths shared one cause: each opened a **blank** window (`window.open()` with no address) and then assigned its `location`. That is a browser idiom for dropping the opener, but the desktop shell routes a window by the address it is handed, so what it received was `about:blank` — an external address, handed to the system browser, with the real link discarded. The terminal now opens the address itself in one step, with `noopener,noreferrer`.+- Hyperlinks written by a program (OSC 8) had no handler at all, which is why xterm was falling back to that warning prompt. They go through the same opener now, so both kinds of link behave alike.+- Clicking a link inside a full-screen program — an agent CLI, anything with a spinner — did nothing at all, with or without the above: such a program redraws every frame, and xterm only activates a link when the object under the pointer at mouseup is the same one it saw at mousedown, which a redraw replaces. Any click a human can make spans a redraw. The terminal now decides a click by position instead, the way Windows Terminal does: xterm's own providers still say where the links are, and a click whose down and up both land on one opens it — a fact a redraw does not change, since the program redraws the same link in the same place. A drag across a link is still a selection.+- Only `http:` and `https:` are opened. Terminal output belongs to a program, not to the reader, and `javascript:` or `data:` is as easy for it to print as an ordinary address; anything else is ignored silently.++## Copying inside a program++A program's own copy now reaches the system clipboard. tmux's copy mode, and any program that copies for itself, announce the copy to the outer terminal with OSC 52; Windows Terminal honours it and this terminal did not, so a selection made inside tmux went to tmux's buffer and no further. The terminal now accepts OSC 52 **writes** only — the same mechanism also lets a program ask to *read* the clipboard, and terminal output is not something to hand the clipboard's contents to.++## tmux before 3.4++tmux 3.3 and earlier strip OSC 8 hyperlinks from what they display, so a link whose visible text is not its address (`gh`'s "PR #555" style) cannot be clicked in any terminal under such a tmux. tmux 3.4+ passes them through when it believes the outer terminal can show them, which for `TERM=xterm-256color` needs `set -as terminal-features 'xterm*:hyperlinks'` in `~/.tmux.conf`.diff --git a/changelog/unreleased/2026-08-30-terminal-links.zh.md b/changelog/unreleased/2026-08-30-terminal-links.zh.mdnew file mode 100644index 00000000..c8d75ba8--- /dev/null+++ b/changelog/unreleased/2026-08-30-terminal-links.zh.md@@ -0,0 +1,25 @@+# 终端里的链接会打开它指向的地方++- **Date:** 2026-08-30+- **Type:** fix+- **Scope:** `web`+- **PR:** [#556](https://github.com/Prism-Shadow/penguin-harness/pull/556)++[English](2026-08-30-terminal-links.md)++在终端里点击一个 URL,打开的是 `about:blank` 而不是该地址;而由程序写出的超链接——`gh` 和各种 agent CLI 打印 Pull Request 时用的那种——会先问"Do you want to navigate to …? WARNING: This link could potentially be dangerous",无论选什么都毫无反应。++## 细节++- 两条路径同一个原因:它们都先打开一个**空白**窗口(不带地址的 `window.open()`),再给它赋 `location`。这在浏览器里是甩掉 opener 的惯用写法,但桌面壳是按拿到的地址来路由窗口的,于是它收到的是 `about:blank`——一个外部地址,被交给系统浏览器,真正的链接则被丢弃。现在终端一步到位地打开该地址本身,并带上 `noopener,noreferrer`。+- 程序写出的超链接(OSC 8)此前根本没有处理器,这正是 xterm 退回到那个警告弹窗的原因。它们现在走同一个打开器,两类链接行为一致。+- 在全屏程序里——agent CLI,或任何带 spinner 的程序——点击链接原本完全没有反应,与上述两点无关:这类程序每帧都重绘,而 xterm 只在"抬起时指针下的链接对象和按下时是同一个"才激活链接,重绘恰恰会把它换掉。人手能做出的任何一次点击都会跨过一次重绘。现在终端改为按位置判定点击,与 Windows Terminal 一致:链接在哪仍由 xterm 自己的探测器报告,按下与抬起都落在同一个链接上就打开它——重绘不会改变这一事实,因为程序把同一个链接重绘在同一个位置。横跨链接的拖拽仍然是选区。+- 只打开 `http:` 与 `https:`。终端输出属于程序而不属于读者,它打印 `javascript:` 或 `data:` 和打印一个普通地址一样容易;其余一律静默忽略。++## 在程序内部复制++程序自己的复制现在会进入系统剪贴板。tmux 的 copy mode,以及任何自行复制的程序,会用 OSC 52 把复制内容通告给外层终端;Windows Terminal 支持而本终端此前不支持,于是在 tmux 里做的选区只进了 tmux 的 buffer 就止步了。终端现在只接受 OSC 52 的**写入**——同一机制还允许程序请求*读取*剪贴板,而终端输出不是该把剪贴板内容交给它的对象。++## 3.4 之前的 tmux++tmux 3.3 及更早版本会从其显示内容中剥掉 OSC 8 超链接,因此可见文本不是地址本身的链接(`gh` 那种 "PR #555" 样式)在这类 tmux 之下、无论什么终端都无法点击。tmux 3.4+ 会在认为外层终端能显示超链接时转发它们;对 `TERM=xterm-256color` 需要在 `~/.tmux.conf` 里加 `set -as terminal-features 'xterm*:hyperlinks'`。diff --git a/packages/web/package.json b/packages/web/package.jsonindex ac1a1587..a826cdbe 100644--- a/packages/web/package.json+++ b/packages/web/package.json@@ -16,6 +16,7 @@"@prismshadow/penguin-core": "workspace:*","@shikijs/langs": "^4.3.1","@shikijs/themes": "^4.3.1",+ "@xterm/addon-clipboard": "^0.1.0","@xterm/addon-fit": "^0.10.0","@xterm/addon-web-links": "^0.11.0","@xterm/xterm": "^5.5.0",diff --git a/packages/web/src/features/terminal/terminal-links.ts b/packages/web/src/features/terminal/terminal-links.tsnew file mode 100644index 00000000..484ec769--- /dev/null+++ b/packages/web/src/features/terminal/terminal-links.ts@@ -0,0 +1,156 @@+/**+ * Opening a link a terminal printed.+ *+ * Two kinds arrive here and both used to be broken:+ *+ * - **A URL in the output**, found by the web-links addon. Its built-in handler opens a+ * BLANK window first (`window.open()` with no argument), clears `opener`, then assigns+ * `location.href`. In a browser that is a way to get an opener-less tab; inside the+ * desktop shell it is a link to `about:blank`, which the shell's window-open handler sees+ * as an external address and hands to the system browser — so the address bar said+ * `about:` and the real link never opened. `noopener` on a real `window.open` does the+ * same job in one step, and hands the shell the address it is actually meant to route.+ * - **An OSC 8 hyperlink**, which is how a program that knows it is on a capable terminal+ * writes a link — `gh`, and the agent CLIs printing a pull request. xterm routes those to+ * `linkHandler`, and with none set it falls back to a `confirm()` warning.+ *+ * The scheme check is the point, not decoration: a terminal's output is not trusted input.+ * A program can print `javascript:` or `data:` as easily as `https:`, and this is exactly+ * the sink xterm's own documentation warns to validate.+ *+ * ## Why the click is handled here and not left to xterm+ *+ * xterm activates a link when the link object under the pointer at mouseup is the SAME+ * object it saw at mousedown — and it drops that object whenever the buffer changes. A+ * full-screen program redraws every frame (a spinner, a status line: every agent CLI does+ * this), so any click a human can make spans a redraw, and the identity check fails every+ * time. Measured: a 0ms down/up activated the link, a 30ms one did not. Windows Terminal+ * resolves the link under the pointer at the moment of the click instead, and that is the+ * experience this reproduces: xterm's own providers still say WHERE the links are (their+ * hover callbacks hand over the text and the buffer range), and `LinkClickTracker` decides+ * whether a click landed on one by position — a fact that survives a redraw, since the+ * program redraws the same link in the same place.+ */++/** Whether a link a terminal printed may be opened at all. */+export function isOpenableLink(uri: string): boolean {+ let url: URL;+ try {+ url = new URL(uri);+ } catch {+ return false; // Not absolute: nothing to navigate to.+ }+ return url.protocol === "http:" || url.protocol === "https:";+}++/**+ * Opens a link from terminal output in a new tab, or does nothing when it is not one of the+ * two schemes a page may be at. Silent on refusal: the output that produced it is a+ * program's, not the reader's, and there is nothing for them to act on.+ */+export function openTerminalLink(uri: string): void {+ if (!isOpenableLink(uri)) return;+ window.open(uri, "_blank", "noopener,noreferrer");+}++/** A cell in xterm's link coordinates: 1-based column, 1-based row plus the scroll offset. */+export interface LinkPosition {+ x: number;+ y: number;+}++/** A link's extent, as xterm's providers report it: both ends inclusive, in LinkPosition terms. */+export interface LinkRange {+ start: LinkPosition;+ end: LinkPosition;+}++/**+ * xterm's own containment rule, kept in the same shape it uses: the range and the point+ * are flattened to a cell index across the row width, so a link that wraps across rows is+ * one interval rather than a rectangle.+ */+export function rangeContains(range: LinkRange, cols: number, pos: LinkPosition): boolean {+ const start = range.start.y * cols + range.start.x;+ const end = range.end.y * cols + range.end.x;+ const at = pos.y * cols + pos.x;+ return start <= at && at <= end;+}++/**+ * Where a pointer event landed, in link coordinates, given the screen box and the size of+ * the terminal grid. The screen element is sized to exactly cols × rows cells, so the cell+ * size falls out of its box — no reach into xterm's renderer for its private dimensions.+ */+export function positionFromPointer(+ client: { x: number; y: number },+ screen: { left: number; top: number; width: number; height: number },+ grid: { cols: number; rows: number; viewportY: number },+): LinkPosition | null {+ if (grid.cols <= 0 || grid.rows <= 0 || screen.width <= 0 || screen.height <= 0) return null;+ const col = Math.floor(((client.x - screen.left) / screen.width) * grid.cols);+ const row = Math.floor(((client.y - screen.top) / screen.height) * grid.rows);+ if (col < 0 || col >= grid.cols || row < 0 || row >= grid.rows) return null;+ return { x: col + 1, y: row + 1 + grid.viewportY };+}++/** How far a pointer may travel between down and up and still be a click, not a drag. */+export const CLICK_SLOP_PX = 4;++/**+ * Turns hover reports and pointer events into "the reader clicked this link".+ *+ * The hover callbacks are xterm telling us where a link is. That knowledge is kept past+ * xterm's own `leave` — a redraw fires `leave` for a link that is still there — and is+ * retired only when the pointer is seen outside the range, or when a different link is+ * hovered. A click opens the remembered link when both its down and its up landed inside+ * that range, with the pointer having moved no further than a click allows.+ */+export class LinkClickTracker {+ #hovered: { text: string; range: LinkRange } | null = null;+ #down: { pos: LinkPosition; clientX: number; clientY: number } | null = null;++ constructor(private readonly cols: () => number) {}++ /** xterm found a link under the pointer. */+ hover(text: string, range: LinkRange): void {+ this.#hovered = { text, range };+ }++ /**+ * xterm stopped tracking a link. Deliberately not forgotten here: this fires on every+ * redraw of a still-present link, which is the very case the tracker exists for. The+ * pointer's own movement retires it (see `move`).+ */+ leave(): void {}++ /** The pointer moved to `pos` (null: off the grid). */+ move(pos: LinkPosition | null): void {+ if (this.#hovered === null) return;+ if (pos === null || !rangeContains(this.#hovered.range, this.cols(), pos)) {+ this.#hovered = null;+ }+ }++ /** Primary button went down at `pos`. */+ down(pos: LinkPosition | null, clientX: number, clientY: number): void {+ this.#down = pos === null ? null : { pos, clientX, clientY };+ }++ /**+ * Primary button came up at `pos`. Answers the link to open, or null. The down is+ * consumed either way: a mouseup never opens on the strength of an earlier click.+ */+ up(pos: LinkPosition | null, clientX: number, clientY: number): string | null {+ const down = this.#down;+ this.#down = null;+ const link = this.#hovered;+ if (down === null || pos === null || link === null) return null;+ const moved = Math.hypot(clientX - down.clientX, clientY - down.clientY);+ if (moved > CLICK_SLOP_PX) return null; // A drag, even a short one, is a selection.+ const cols = this.cols();+ if (!rangeContains(link.range, cols, down.pos)) return null;+ if (!rangeContains(link.range, cols, pos)) return null;+ return link.text;+ }+}diff --git a/packages/web/src/features/terminal/terminal-view.tsx b/packages/web/src/features/terminal/terminal-view.tsxindex 0a8b92c4..a2de5f01 100644--- a/packages/web/src/features/terminal/terminal-view.tsx+++ b/packages/web/src/features/terminal/terminal-view.tsx@@ -16,6 +16,7 @@ import "@xterm/xterm/css/xterm.css";// Types only (erased at compile time): the xterm runtime stays behind loadXterm() below.import type { ITheme, Terminal as XTerminal } from "@xterm/xterm";import { TerminalOpcode, decodeFrame, encodeFrame, encodeResize } from "./terminal-frames";+import { LinkClickTracker, openTerminalLink, positionFromPointer } from "./terminal-links";import { useTheme } from "../../state/theme";/**@@ -30,6 +31,7 @@ function loadXterm() {import("@xterm/xterm"),import("@xterm/addon-fit"),import("@xterm/addon-web-links"),+ import("@xterm/addon-clipboard"),]);}@@ -226,7 +228,7 @@ export function TerminalView({ ensure, onStatus, onInfo, onTitle, className }: T};async function startTerminal(container: HTMLDivElement): Promise<() => void> {- const [{ Terminal }, { FitAddon }, { WebLinksAddon }] = await loadXterm();+ const [{ Terminal }, { FitAddon }, { WebLinksAddon }, { ClipboardAddon }] = await loadXterm();let disposed = false;let socket: WebSocket | null = null;let exited = false;@@ -234,6 +236,10 @@ export function TerminalView({ ensure, onStatus, onInfo, onTitle, className }: Tconst report = (status: TerminalStatus, detail = ""): void => {if (!disposed) callbacks.current.onStatus?.(status, detail);};+ /** Resolves clicks on links by position (terminal-links.ts); fed by the providers' hover reports. */+ const links = new LinkClickTracker(() => term.cols);+ /** One abort for every DOM listener this terminal registers; fired at teardown. */+ const listenerAbort = new AbortController();const term = new Terminal({allowProposedApi: true,@@ -244,14 +250,77 @@ export function TerminalView({ ensure, onStatus, onInfo, onTitle, className }: TlineHeight: 1.2,scrollback: 5000,theme: terminalTheme(darkRef.current),+ // OSC 8 hyperlinks — how a program that knows the terminal is capable writes a link.+ // The providers only REPORT links here; the click itself is resolved below by+ // position, because xterm's own activation cannot survive a redrawing program+ // (terminal-links.ts). `activate` stays a no-op so a click never opens twice.+ linkHandler: {+ activate: () => {},+ hover: (_event, text, range) => links.hover(text, range),+ leave: () => links.leave(),+ },});const fit = new FitAddon();term.loadAddon(fit);- term.loadAddon(new WebLinksAddon());+ // Same arrangement for URLs found in the output: the addon reports, the tracker+ // decides. Its built-in handler would also have opened a blank window first, which+ // the desktop shell reads as a link to about:blank.+ term.loadAddon(+ new WebLinksAddon(() => {}, {+ hover: (_event, text, range) => links.hover(text, range),+ leave: () => links.leave(),+ }),+ );+ // OSC 52: a program's own copy reaches the system clipboard — what tmux's copy mode+ // does on every copy, and what makes a selection inside tmux land where a person+ // expects it. WRITE only. The addon's default provider also answers a program's+ // request to READ the clipboard, and terminal output is not something to hand the+ // clipboard's contents to.+ term.loadAddon(+ new ClipboardAddon({+ readText: () => Promise.resolve(""),+ writeText: (_selection, text) =>+ navigator.clipboard?.writeText(text).catch(() => {}) ?? Promise.resolve(),+ }),+ );termRef.current = term;term.open(container);fit.fit();+ // Where a pointer event landed, in the coordinates the link ranges use. The screen+ // element is exactly cols × rows cells, so the cell size falls out of its box.+ const linkPosition = (event: MouseEvent) => {+ const screen = term.element?.querySelector(".xterm-screen");+ if (!screen) return null;+ const box = screen.getBoundingClientRect();+ return positionFromPointer(+ { x: event.clientX, y: event.clientY },+ { left: box.left, top: box.top, width: box.width, height: box.height },+ { cols: term.cols, rows: term.rows, viewportY: term.buffer.active.viewportY },+ );+ };+ const linkTarget = term.element;+ if (linkTarget) {+ const opts = { signal: listenerAbort.signal };+ linkTarget.addEventListener("mousemove", (e) => links.move(linkPosition(e)), opts);+ linkTarget.addEventListener(+ "mousedown",+ (e) => {+ if (e.button === 0) links.down(linkPosition(e), e.clientX, e.clientY);+ },+ opts,+ );+ linkTarget.addEventListener(+ "mouseup",+ (e) => {+ if (e.button !== 0) return;+ const uri = links.up(linkPosition(e), e.clientX, e.clientY);+ if (uri !== null) openTerminalLink(uri);+ },+ opts,+ );+ }+/** Copies the active selection and clears it — the visual ack that the copy happened. */const copySelection = (): void => {const selection = term.getSelection();@@ -303,7 +372,6 @@ export function TerminalView({ ensure, onStatus, onInfo, onTitle, className }: T* htop) has turned mouse tracking on — the app owns the pointer then, and xterm* forwards the events as escape codes.*/- const listenerAbort = new AbortController();const { signal } = listenerAbort;const appOwnsMouse = (): boolean => term.modes.mouseTrackingMode !== "none";container.addEventListener(diff --git a/packages/web/test/terminal-links.test.ts b/packages/web/test/terminal-links.test.tsnew file mode 100644index 00000000..709760d9--- /dev/null+++ b/packages/web/test/terminal-links.test.ts@@ -0,0 +1,184 @@+/**+ * Opening a link a terminal printed (features/terminal/terminal-links.ts).+ *+ * Terminal output is a program's, not the reader's, so the scheme check is the load-bearing+ * part: a `javascript:` or `data:` link is as easy to print as an `https:` one, and this is+ * the sink xterm's own documentation warns to validate. The other half is that a real URL is+ * opened DIRECTLY — the addon's built-in handler opens a blank window first and navigates+ * it, which inside the desktop shell became a link to `about:blank`.+ */+import { afterEach, describe, expect, it, vi } from "vitest";+import {+ CLICK_SLOP_PX,+ LinkClickTracker,+ isOpenableLink,+ openTerminalLink,+ positionFromPointer,+ rangeContains,+} from "../src/features/terminal/terminal-links";++afterEach(() => {+ vi.unstubAllGlobals();+});++/** Records what window.open was asked to do. */+function stubWindowOpen(): { calls: [string, string, string][] } {+ const calls: [string, string, string][] = [];+ vi.stubGlobal("window", {+ open: (url: string, target: string, features: string) => {+ calls.push([url, target, features]);+ return null;+ },+ });+ return { calls };+}++describe("isOpenableLink", () => {+ it("accepts the two schemes a page may be at", () => {+ expect(isOpenableLink("https://github.com/o/r/pull/555")).toBe(true);+ expect(isOpenableLink("http://localhost:7364/")).toBe(true);+ });++ it("refuses everything a program could print to make the terminal act", () => {+ for (const uri of [+ "javascript:alert(1)",+ "data:text/html,<script>alert(1)</script>",+ "file:///etc/passwd",+ "vscode://file/etc/passwd",+ "about:blank",+ "",+ "github.com/o/r",+ ]) {+ expect(isOpenableLink(uri)).toBe(false);+ }+ });+});++describe("openTerminalLink", () => {+ it("opens the URL itself, in one step, with no opener", () => {+ // The regression: the addon's own handler opens `window.open()` with NO url — a blank+ // window — and then assigns location.href. The shell routes by the url it is handed, so+ // that one arrived as about:blank and the real link never opened.+ const { calls } = stubWindowOpen();+ openTerminalLink("https://github.com/o/r/pull/555");+ expect(calls).toEqual([["https://github.com/o/r/pull/555", "_blank", "noopener,noreferrer"]]);+ });++ it("opens nothing at all for a scheme it refuses", () => {+ const { calls } = stubWindowOpen();+ openTerminalLink("javascript:alert(1)");+ openTerminalLink("about:blank");+ expect(calls).toEqual([]);+ });+});++describe("positionFromPointer", () => {+ const screen = { left: 10, top: 20, width: 800, height: 480 }; // 80 × 24 cells of 10 × 20+ const grid = { cols: 80, rows: 24, viewportY: 0 };++ it("maps a pointer to the 1-based cell under it, adding the scroll offset to the row", () => {+ expect(positionFromPointer({ x: 10, y: 20 }, screen, grid)).toEqual({ x: 1, y: 1 });+ expect(positionFromPointer({ x: 35, y: 45 }, screen, grid)).toEqual({ x: 3, y: 2 });+ expect(positionFromPointer({ x: 809, y: 499 }, screen, grid)).toEqual({ x: 80, y: 24 });+ // A scrolled viewport: the row is the buffer line xterm's providers report ranges in.+ expect(positionFromPointer({ x: 35, y: 45 }, screen, { ...grid, viewportY: 18 })).toEqual({+ x: 3,+ y: 20,+ });+ });++ it("answers null off the grid, and for a grid that has no size yet", () => {+ expect(positionFromPointer({ x: 9, y: 20 }, screen, grid)).toBeNull();+ expect(positionFromPointer({ x: 10, y: 500 }, screen, grid)).toBeNull();+ expect(positionFromPointer({ x: 10, y: 20 }, { ...screen, width: 0 }, grid)).toBeNull();+ expect(positionFromPointer({ x: 10, y: 20 }, screen, { ...grid, cols: 0 })).toBeNull();+ });+});++describe("rangeContains", () => {+ it("is inclusive at both ends and treats a wrapped link as one interval, like xterm", () => {+ const range = { start: { x: 78, y: 5 }, end: { x: 3, y: 6 } }; // wraps from row 5 into row 6+ expect(rangeContains(range, 80, { x: 78, y: 5 })).toBe(true);+ expect(rangeContains(range, 80, { x: 80, y: 5 })).toBe(true);+ expect(rangeContains(range, 80, { x: 1, y: 6 })).toBe(true);+ expect(rangeContains(range, 80, { x: 3, y: 6 })).toBe(true);+ expect(rangeContains(range, 80, { x: 77, y: 5 })).toBe(false);+ expect(rangeContains(range, 80, { x: 4, y: 6 })).toBe(false);+ });+});++describe("LinkClickTracker", () => {+ const URL = "https://github.com/o/r/pull/555";+ const range = { start: { x: 3, y: 41 }, end: { x: 9, y: 41 } };+ const inside = { x: 5, y: 41 };+ const outside = { x: 20, y: 41 };+ const tracker = () => new LinkClickTracker(() => 80);++ it("opens the hovered link on a click that stays inside it", () => {+ const t = tracker();+ t.hover(URL, range);+ t.down(inside, 100, 100);+ expect(t.up(inside, 101, 100)).toBe(URL);+ });++ it("keeps the link across xterm's leave — a redraw of a still-present link", () => {+ // The regression this exists for: xterm forgets the link on every redraw, and a+ // full-screen program redraws between any human mousedown and mouseup.+ const t = tracker();+ t.hover(URL, range);+ t.down(inside, 100, 100);+ t.leave();+ t.leave();+ expect(t.up(inside, 100, 100)).toBe(URL);+ });++ it("forgets the link once the pointer is seen outside it", () => {+ const t = tracker();+ t.hover(URL, range);+ t.move(outside);+ t.down(inside, 100, 100);+ expect(t.up(inside, 100, 100)).toBeNull();+ // Off the grid entirely counts as outside too.+ t.hover(URL, range);+ t.move(null);+ t.down(inside, 100, 100);+ expect(t.up(inside, 100, 100)).toBeNull();+ });++ it("a drag is a selection, not a click, however short", () => {+ const t = tracker();+ t.hover(URL, range);+ t.down(inside, 100, 100);+ expect(t.up(inside, 100 + CLICK_SLOP_PX + 1, 100)).toBeNull();+ t.down(inside, 100, 100);+ expect(t.up(inside, 100, 100 - CLICK_SLOP_PX)).toBe(URL); // within the slop: still a click+ });++ it("needs both ends of the click on the link", () => {+ const t = tracker();+ t.hover(URL, range);+ t.down(outside, 100, 100);+ expect(t.up(inside, 100, 100)).toBeNull();+ t.down(inside, 100, 100);+ expect(t.up(outside, 100, 100)).toBeNull();+ t.down(null, 100, 100);+ expect(t.up(inside, 100, 100)).toBeNull();+ });++ it("consumes the down: a mouseup never opens on the strength of an earlier click", () => {+ const t = tracker();+ t.hover(URL, range);+ t.down(inside, 100, 100);+ expect(t.up(inside, 100, 100)).toBe(URL);+ expect(t.up(inside, 100, 100)).toBeNull();+ });++ it("follows the most recently hovered link", () => {+ const t = tracker();+ const other = { start: { x: 3, y: 42 }, end: { x: 9, y: 42 } };+ t.hover(URL, range);+ t.hover("https://example.com/x", other);+ t.down({ x: 5, y: 42 }, 100, 100);+ expect(t.up({ x: 5, y: 42 }, 100, 100)).toBe("https://example.com/x");+ });+});diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 523493b1..a7c40fd8 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -371,6 +371,9 @@ importers:'@shikijs/themes':specifier: ^4.3.1version: 4.3.1+ '@xterm/addon-clipboard':+ specifier: ^0.1.0+ version: 0.1.0(@xterm/[email protected])'@xterm/addon-fit':specifier: ^0.10.0version: 0.10.0(@xterm/[email protected])@@ -1579,6 +1582,11 @@ packages:engines: {node: '>=10.0.0'}deprecated: this version has critical issues, please update to the latest version+ '@xterm/[email protected]':+ resolution: {integrity: sha512-zdoM7p53T5sv/HbRTyp4hY0kKmEQ3MZvAvEtiXqNIHc/JdpqwByCtsTaQF5DX2n4hYdXRPO4P/eOS0QEhX1nPw==}+ peerDependencies:+ '@xterm/xterm': ^5.4.0+'@xterm/[email protected]':resolution: {integrity: sha512-UFYkDm4HUahf2lnEyHvio51TNGiLK66mqP2JoATy7hRZeXaGMRDr00JiSF7m63vR5WKATF605yEggJKsw0JpMQ==}peerDependencies:@@ -2513,6 +2521,9 @@ packages:resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==}engines: {node: '>=10'}+ resolution: {integrity: sha512-uwYQp+VJ38FVvtim6qNbit6e9uT6dwWQ4Y1+H9TxhW5hcHjpHwoxlR0nMpqUmIFOmu4VqMxwdJA88gIVuZJQ/g==}+resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}@@ -5361,6 +5372,11 @@ snapshots:'@xmldom/[email protected]': {}+ '@xterm/[email protected](@xterm/[email protected])':+ dependencies:+ '@xterm/xterm': 5.5.0+ js-base64: 3.9.3+'@xterm/[email protected](@xterm/[email protected])':dependencies:'@xterm/xterm': 5.5.0@@ -6509,6 +6525,8 @@ snapshots:+ [email protected]: {}+