fix: deliver Ctrl+V paste through terminal.input

Hand the bracketed frame to the target terminal with input() so onData
scrolls to the bottom, clears the selection, and delivers the bytes.
The paste trap no longer writes the frame itself.

Fixes #716

Co-authored-by: DDT <1786035110@qq.com>
This commit is contained in:
DDTandDDT committed 2026-10-28 07:09:35 +00:00
1 parent dd09a383f1
commit 6f820ca990
6 files changed
+120 -80

No files matched your search

+12 -50
View File
@@ -193,7 +193,10 @@ Object.assign(CodemanApp.prototype, {
// the result for images. Works on plain HTTP (no Clipboard API needed).
// `target` names the terminal the Ctrl+V came from and its session; both
// default to the primary pane. A second terminal (the split pane) passes its
// own, so text pastes into THAT xterm and images upload to THAT session.
// own. Images upload to THAT session. Plain text goes to that pane's session
// as a Codeman-built bracketed-paste frame: the terminal is only refocused
// and receives input(framed). onData delivers the frame; it is not written
// into the xterm buffer.
_handleImagePaste(target = {}) {
const self = this;
const terminal = target.terminal || this.terminal;
@@ -244,14 +247,17 @@ Object.assign(CodemanApp.prototype, {
if (imageFiles.length > 0) {
self._uploadAndInsertImages(imageFiles, { sessionId: sessionId });
} else if (text) {
} else if (text && terminal) {
// No image. xterm's paste() emits CSI 200~/201~ only while its DECSET
// 2004 mirror is on, and a terminal replay clears that mirror, so the
// markers never arrive and a copied newline submits (#716). Build the
// frame here, the same bytes keyboard-accessory.js sends, and deliver
// it on the session input path. Do not useMux: the mux fallback strips
// every \r, which is the line separator inside the frame.
self._deliverBracketedPaste(sessionId, text);
// frame here and hand it to this terminal through input(). That fires
// onData as user input (scroll to the bottom, clear the selection).
// The main pane's bracketed-paste branch and a tile's _onTerminalData
// deliver it, including the local-echo flush (#219). Do not also write
// the frame from here.
const body = text.replace(/\x1b\[20[01]~/g, '').replace(/\r?\n/g, '\r');
terminal.input(`\x1b[200~${body}\x1b[201~`);
}
});
@@ -260,50 +266,6 @@ Object.assign(CodemanApp.prototype, {
document.execCommand('paste');
},
/**
* Plain-text Ctrl+V as one bracketed paste on the session-bound input path.
* Mirrors keyboard-accessory.js `_sendBracketedPaste`: drop nested 200/201
* markers (a clipboard carrying ESC[201~ would end the bracket early), map
* newlines to CR (what xterm's prepareTextForTerminal did), wrap with
* CSI 200~ / CSI 201~. The composer's length cap is not applied here;
* `_sendInputAsync` already splits a large paste and refuses one past its
* own ceiling.
*
* When the local-echo overlay owns this session's prompt, flush its unsent
* text first and delay the frame. That is the onData bracketed-paste branch
* (#219): Codex drops bytes that share a PTY read with a bracketed paste,
* and the typed prefix has to land ahead of the block.
*/
_deliverBracketedPaste(sessionId, text) {
if (!sessionId || typeof text !== 'string' || text === '' || typeof this._sendInputAsync !== 'function') return;
try {
this._predictiveEcho?.clearPredictions?.();
} catch {
// Predictions are visual only.
}
const pasteText = text.replace(/\x1b\[20[01]~/g, '').replace(/\r?\n/g, '\r');
const framed = `\x1b[200~${pasteText}\x1b[201~`;
const echoOwns =
this.activeSessionId === sessionId &&
this._localEchoEnabled &&
this._localEchoOverlay &&
!this._echoPassthroughSessions?.has?.(sessionId) &&
!this._tilesOwnTerminal?.() &&
typeof this._flushLocalEchoPending === 'function';
if (echoOwns) {
const hadPending = !!this._localEchoOverlay.pendingText;
this._flushLocalEchoPending();
if (hadPending) {
const prefix = this._pendingInput || '';
this._pendingInput = '';
if (prefix) this._sendInputAsync(sessionId, prefix);
setTimeout(() => this._sendInputAsync(sessionId, framed), 80);
return;
}
}
this._sendInputAsync(sessionId, framed);
},
/** What a pick or a paste may upload: 'image', 'video' for the camera roll's
* clips (the server streams those to disk under their own cap), 'document'
* for the office and text files the server admits, else null. The one filter
+4 -3
View File
@@ -344,9 +344,10 @@
if (global.app?.tileShortcutFor?.(ev)) return false;
// Ctrl+V / Cmd+V: the primary pane's paste trap, aimed at THIS pane, so
// a pasted image uploads to this pane's session and its path is typed
// here, and pasted text goes into this xterm with its bracketed-paste
// markers intact. Mirrors terminal-ui.js's own Ctrl+V gate; without it
// xterm's default only ever pasted text.
// here. Plain text goes to this pane's session as a Codeman-built
// bracketed-paste frame; this terminal is only refocused and receives
// input(framed), which onData delivers. Mirrors terminal-ui.js's own
// Ctrl+V gate; without it xterm's default only ever pasted text.
if ((ev.ctrlKey || ev.metaKey) && ev.key === 'v' && ev.type === 'keydown') {
global.app?._handleImagePaste?.({ terminal: this.terminal, sessionId: this.sessionId });
return false;