Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.
TypeScript claude-code-mod
Links: an open that fails late does not copy over a newer copy
razorback16a8c7f4dcedd8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex aad9cdf..d61d94e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,7 +6,7 @@ All releases of Intelligent UI for Claude Code (`cc-intelligent-ui`). Claude Cod### New-- **A click opens a link or a file.** With picture select, a plain click on a web link opens it in the browser (`open` on macOS, `xdg-open` on Linux). A plain click on a file path opens it in your editor, at the line and column of the path. Alt+click copies the link or path, as a click did before. A click on a command or a code block's copy button still copies, and a drag still selects text. If the open fails, the mod copies the target and the toast says so. Over ssh, a click copies. In iTerm2, Option+click goes to the terminal's own selection, so alt+click may not reach the mod there. Refer to [Click a link, a file or a command](docs/usage.md#click-a-link-a-file-or-a-command).+- **A click opens a link or a file.** With picture select, a plain click on a web link opens it in the browser (`open` on macOS, `xdg-open` on Linux). A plain click on a file path opens it in your editor, at the line and column of the path. Alt+click copies the link or path, as a click did before. A click on a command or a code block's copy button still copies, and a drag still selects text. If the open fails, the mod copies the target and the toast says so, but not over a newer copy that came while it tried to open. Over ssh, a click copies. In iTerm2, Option+click goes to the terminal's own selection, so alt+click may not reach the mod there. Refer to [Click a link, a file or a command](docs/usage.md#click-a-link-a-file-or-a-command).- **`/iui editor`.** Sets the editor for file paths. `auto` (the default) uses the first editor on the PATH: `code`, `code-insiders`, `codium`, `cursor`, `windsurf`, `zed`, `zeditor`, `subl`, `idea`, `webstorm`, `pycharm`, `goland`, `clion`, `rider`; with none, the system default app. `/iui editor <name>` picks one, `/iui editor default` uses the system default app, and `/iui editor <command with {path} {line} {column}>` runs your own command (split on spaces, no shell). The setting is kept across sessions.- **A preview of pasted image paths.** When you paste the path of an image file (path text that you copied), Claude Code shows `[Image #N]` but writes no file until you send the prompt. The mod now reads the clipboard one time to find the file, and shows its preview. Absolute paths, `~/` paths, paths from the session folder, `file://` URLs, quoted paths and paths with escaped spaces work. It shows PNG, JPEG and WebP files (JPEG and WebP need Typst).diff --git a/hooks/register.tsx b/hooks/register.tsxindex ec7305f..aec579d 100644--- a/hooks/register.tsx+++ b/hooks/register.tsx@@ -679,7 +679,7 @@ async function clickAt($: EngineInterface, d: Drawn & { job?: Job }, post: Selecif (opens) {// An open writes no clipboard: the turn is not claimed.turn.done()- await openTarget($, target, surface)+ await openTarget($, target, surface, turn)return}const mine = await claim(turn)@@ -692,14 +692,17 @@ async function clickAt($: EngineInterface, d: Drawn & { job?: Job }, post: Selec}// A web link or a file opened (clickAt), with its toast. One that does not-// open (no program, an exit code not 0) is copied.-async function openTarget($: EngineInterface, target: Target, surface: RenderSurface) {+// open (no program, an exit code not 0) is copied in the click's turn: a+// newer copy (or a new native selection) while it opened keeps the clipboard.+async function openTarget($: EngineInterface, target: Target, surface: RenderSurface, turn: Turn) {const use: Use = target.kind === 'file' ? await editorNow($) : { kind: 'app' }const argv = openArgv(target, { isMac: !!S.env?.isMac, use })const got = argv ? await exec($, detachedArgv(argv), { timeoutMs: OPEN_TIMEOUT_MS }).catch(() => null) : nullif (S.debug) traceDebug($, `select: open ${argv?.join(' ') ?? 'none'} exit ${got ? got.exitCode : 'failed'}`)if (got?.exitCode === 0) return void toast($, openedText(target, use))- claimNow($, nativeNow($))+ if (!(await claim(turn)) || !(await isNewest($, turn))) {+ return void toast($, `Intelligent UI: could not open the ${target.kind === 'web' ? 'link' : 'file'}`)+ }await copyTarget($, target, surface, true)}diff --git a/tests/copy.test.ts b/tests/copy.test.tsindex 8c4828f..60c6a2f 100644--- a/tests/copy.test.ts+++ b/tests/copy.test.ts@@ -641,6 +641,10 @@ function world(hold() {w.gate = new Promise<void>(r => (w.release = r))},+ openGate: null as Promise<void> | null, releaseOpens: () => {},+ holdOpens() {+ w.openGate = new Promise<void>(r => (w.releaseOpens = r))+ },readGate: null as Promise<void> | null, releaseReads: () => {},holdReads() {w.readGate = new Promise<void>(r => (w.releaseReads = r))@@ -735,6 +739,7 @@ function world(// A click's open, detached (no editor is on the PATH: the system app).if (argv[0] === 'sh' && argv[2] === DETACH_SH && argv[4] === 'open') {w.opens.push(argv.slice(4))+ if (w.openGate) await w.openGatereturn ok('', w.openFails ? 1 : 0)}if (argv[0] === '/usr/bin/perl' && argv[2] === READ_PL) {@@ -1931,6 +1936,24 @@ test('picture select: a link or a file that does not open is copied, and the toaexpect(w.toasts).toContain('Intelligent UI: could not open the file, so copied its path')})+test('picture select: a link whose open fails late is not copied over a newer copy', async ($, on) => {+ const { w, ui } = await drawTargets($, on)+ w.openFails = true+ w.holdOpens()+ await click(ui, 6, 3)+ await settle(w)+ expect(w.opens.length).toBe(1)+ await click(ui, 11, 8)+ await settle(w)+ expect(w.copies).toEqual(['echo hello\nls -la'])+ w.releaseOpens()+ await settle(w)+ expect(w.copies).toEqual(['echo hello\nls -la'])+ expect(w.clipboard).toBe('echo hello\nls -la')+ expect(w.toasts).toContain('Intelligent UI: could not open the link')+ expect(w.toasts).not.toContain('Intelligent UI: could not open the link, so copied it')+})+test('picture select: a click whose page still reads its words copies nothing after a newer click on a ready page', async ($, on) => {const { w, ui } = await drawTargets($, on)await hover(ui, 52, 4)