pull/16379/merge
Armand Lynch 2026-04-08 05:46:14 +00:00 committed by GitHub
commit 6fc11c1555
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 2 deletions

View File

@ -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"
@ -1084,7 +1094,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()}

View File

@ -101,6 +101,22 @@ export namespace Clipboard {
}
}
export async function readPrimary(): Promise<string | undefined> {
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()