From 6af52e74ab6ad5fec86570cd3515901dd7a1074a Mon Sep 17 00:00:00 2001 From: tanzhenxin Date: Mon, 15 Sep 2025 16:23:10 +0800 Subject: [PATCH] fix: test fix again --- .../cli/src/ui/contexts/KeypressContext.tsx | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/ui/contexts/KeypressContext.tsx b/packages/cli/src/ui/contexts/KeypressContext.tsx index 0b910bc9..e1606abd 100644 --- a/packages/cli/src/ui/contexts/KeypressContext.tsx +++ b/packages/cli/src/ui/contexts/KeypressContext.tsx @@ -363,7 +363,42 @@ export function KeypressProvider({ markerLength = pasteModeSuffixBuffer.length; if (nextMarkerPos === -1) { - keypressStream.write(data.slice(pos)); + // Heuristic fallback for terminals that don't send bracketed paste + // (commonly seen on Windows when using right-click paste). If the + // remaining chunk contains CR/LF or is substantially long, treat it + // as a single paste event so embedded newlines don't trigger submit. + const remaining = data.slice(pos); + const containsNewline = + remaining.includes(0x0a) || remaining.includes(0x0d); + const isLongurst = remaining.length >= 64; // conservative threshold + if (containsNewline || isLongurst) { + const text = remaining.toString('utf8'); + const createPasteKeyEvent = ( + name: 'paste-start' | 'paste-end', + ): Key => ({ + name, + ctrl: false, + meta: false, + shift: false, + paste: false, + sequence: '', + }); + handleKeypress(undefined, createPasteKeyEvent('paste-start')); + handleKeypress(undefined, { + name: '', + ctrl: false, + meta: false, + shift: false, + paste: false, + sequence: text, + }); + handleKeypress(undefined, createPasteKeyEvent('paste-end')); + return; + } + + // Fallback: no paste markers and not a likely paste burst. Pass + // through to readline to decode into key events. + keypressStream.write(remaining); return; }