diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index d63c248fb83..f04dc4a5d44 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -1,4 +1,4 @@ -import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, t, dim, fg } from "@opentui/core" +import { BoxRenderable, TextareaRenderable, MouseEvent, MouseButton, PasteEvent, t, dim, fg } from "@opentui/core" import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js" import "opentui-spinner/solid" import path from "path" @@ -991,7 +991,15 @@ export function Prompt(props: PromptProps) { input.cursorColor = theme.text }, 0) }} - onMouseDown={(r: MouseEvent) => r.target?.focus()} + onMouseDown={async (r: MouseEvent) => { + r.target?.focus() + if (r.button !== MouseButton.MIDDLE) return + if (props.disabled) return + r.preventDefault() + const text = await Clipboard.readPrimary() + if (!text || !input || input.isDestroyed) return + input.insertText(text) + }} focusedBackgroundColor={theme.backgroundElement} cursorColor={theme.text} syntaxStyle={syntax()} diff --git a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts index 1a8197bf4e8..ba93c852173 100644 --- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts +++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts @@ -73,6 +73,24 @@ export namespace Clipboard { } } + export async function readPrimary(): Promise { + const os = platform() + if (os === "linux") { + if (process.env["WAYLAND_DISPLAY"] && Bun.which("wl-paste")) { + const text = await $`wl-paste --primary --no-newline`.nothrow().text() + if (text) return text + } + if (Bun.which("xclip")) { + const text = await $`xclip -selection primary -o`.nothrow().text() + if (text) return text + } + if (Bun.which("xsel")) { + const text = await $`xsel --primary --output`.nothrow().text() + if (text) return text + } + } + } + const getCopyMethod = lazy(() => { const os = platform()