tui: clarify Windows Terminal paste path comments

This commit is contained in:
LukeParkerDev
2026-03-23 11:19:16 +10:00
parent b0cb887df7
commit 601131c3b1
2 changed files with 13 additions and 11 deletions

View File

@@ -356,8 +356,8 @@ export function Prompt(props: PromptProps) {
]
})
// Windows Terminal 1.25+ with kitty keyboard swallows Ctrl+V press but
// leaks the release (CSI 118;modifier;3u). Detect it and probe clipboard.
// Windows Terminal 1.25+ handles Ctrl+V on keydown when kitty events are
// enabled, but still reports the kitty key-release event. Probe on release.
if (process.platform === "win32") {
useKeyboard(
(evt) => {
@@ -864,8 +864,9 @@ export function Prompt(props: PromptProps) {
e.preventDefault()
return
}
// Check clipboard for images before terminal handles the paste.
// On Windows most terminals consume Ctrl+V so this rarely fires.
// Check clipboard for images before terminal-handled paste runs.
// This helps terminals that forward Ctrl+V to the app; Windows
// Terminal 1.25+ usually handles Ctrl+V before this path.
if (keybind.match("input_paste", e)) {
const content = await Clipboard.read()
if (content?.mime.startsWith("image/")) {
@@ -949,8 +950,8 @@ export function Prompt(props: PromptProps) {
const normalizedText = decodePasteBytes(event.bytes).replace(/\r\n/g, "\n").replace(/\r/g, "\n")
const pastedContent = normalizedText.trim()
// Empty paste = image-only clipboard. Stable WT sends an empty
// bracketed paste for this; WT 1.25+ with kitty does not.
// Windows Terminal <1.25 can surface image-only clipboard as an
// empty bracketed paste. Windows Terminal 1.25+ does not.
if (!pastedContent) {
command.trigger("prompt.paste")
return

View File

@@ -30,11 +30,12 @@ export namespace Clipboard {
// Checks clipboard for images first, then falls back to text.
//
// On Windows this is triggered from multiple paths in prompt/ because
// terminals handle Ctrl+V differently:
// 1. Ctrl+V keypress forwarded to app (rare, most terminals consume it)
// 2. Empty bracketed paste (stable WT without kitty sends this for image-only clipboard)
// 3. Kitty Ctrl+V release event (WT 1.25+ swallows the press but leaks the release)
// On Windows prompt/ can call this from multiple paste signals because
// terminals surface image paste differently:
// 1. A forwarded Ctrl+V keypress
// 2. An empty bracketed-paste hint for image-only clipboard in Windows
// Terminal <1.25
// 3. A kitty Ctrl+V key-release fallback for Windows Terminal 1.25+
export async function read(): Promise<Content | undefined> {
const os = platform()