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 382bd2806ec7..38a28efbf71a 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,14 @@ -import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, decodePasteBytes, t, dim, fg } from "@opentui/core" +import { + BoxRenderable, + TextareaRenderable, + MouseEvent, + MouseButton, + PasteEvent, + decodePasteBytes, + t, + dim, + fg, +} from "@opentui/core" import { createEffect, createMemo, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js" import "opentui-spinner/solid" import path from "path" @@ -1080,7 +1090,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 87c0a63abc82..4668f168ca61 100644 --- a/packages/opencode/src/cli/cmd/tui/util/clipboard.ts +++ b/packages/opencode/src/cli/cmd/tui/util/clipboard.ts @@ -101,6 +101,22 @@ export namespace Clipboard { } } + export async function readPrimary(): Promise { + if (platform() !== "linux") return + if (process.env["WAYLAND_DISPLAY"] && which("wl-paste")) { + const result = await Process.text(["wl-paste", "--primary", "--no-newline"], { nothrow: true }) + if (result.text) return result.text + } + if (which("xclip")) { + const result = await Process.text(["xclip", "-selection", "primary", "-o"], { nothrow: true }) + if (result.text) return result.text + } + if (which("xsel")) { + const result = await Process.text(["xsel", "--primary", "--output"], { nothrow: true }) + if (result.text) return result.text + } + } + const getCopyMethod = lazy(() => { const os = platform()