mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-16 19:29:33 +01:00
fix: stop desktop dead-key doubling and bracket Ctrl+V paste
KeyCode 229 recovery forwarded a composed character that xterm had already delivered, so a desktop dead-key backtick arrived twice. create() now attaches only when the primary pointer is coarse. Ctrl+V text paste went through terminal.paste(), which drops the CSI 200~/201~ markers after a replay clears xterm's DECSET 2004 mirror. Plain text is now a hand-built bracketed frame on the session input path. Fixes #716 Co-authored-by: DDT <1786035110@qq.com>
This commit is contained in:
10 files changed
+274
-22
No files matched your search
@@ -244,14 +244,14 @@ Object.assign(CodemanApp.prototype, {
|
||||
|
||||
if (imageFiles.length > 0) {
|
||||
self._uploadAndInsertImages(imageFiles, { sessionId: sessionId });
|
||||
} else {
|
||||
// No image -- route text through xterm's paste() so bracketed-paste
|
||||
// markers (CSI 200~ ... CSI 201~) survive when the inner application
|
||||
// has enabled bracketed-paste mode (Claude Code does). Sending text
|
||||
// via raw sendInput() strips those markers and makes pasted input
|
||||
// indistinguishable from typed input, weakening the CLI's
|
||||
// prompt-injection defenses.
|
||||
if (text && terminal) terminal.paste(text);
|
||||
} else if (text) {
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -260,6 +260,50 @@ 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
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
* that guard, so xterm returns without emitting and the committed character is
|
||||
* silently dropped.
|
||||
*
|
||||
* ⚠ Desktop fine pointers must not run this (#716). xterm already forwards the
|
||||
* composed character, and a second forward doubles a dead-key backtick.
|
||||
* `create()` returns null unless `matchMedia('(pointer: coarse)')` matches, so
|
||||
* soft keyboards keep the recovery and a desktop does not attach it. A missing
|
||||
* or throwing `matchMedia` stands down: a missed recovery is acceptable, a
|
||||
* duplicated keystroke is not.
|
||||
*
|
||||
* ⚠ The gap is NARROWER than "keyCode 229", and assuming otherwise produces a
|
||||
* controller that looks useful while doing nothing. For a keydown that really
|
||||
* does report `keyCode: 229`, xterm ALREADY self-rescues: `CompositionHelper
|
||||
@@ -64,7 +71,20 @@
|
||||
return { deleted: a.length - prefix, inserted: b.slice(prefix).join('') };
|
||||
}
|
||||
|
||||
/**
|
||||
* Touch / coarse pointer only. See the file header: on a fine pointer this
|
||||
* forward runs on top of xterm's own composition handling.
|
||||
*/
|
||||
function isCoarsePointer() {
|
||||
try {
|
||||
return global.matchMedia?.('(pointer: coarse)')?.matches === true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function create(options) {
|
||||
if (!isCoarsePointer()) return null;
|
||||
const textarea = options?.textarea;
|
||||
const emitRecovered = options?.emitRecovered;
|
||||
if (!textarea?.addEventListener || !textarea?.removeEventListener || typeof emitRecovered !== 'function') {
|
||||
|
||||
@@ -646,9 +646,10 @@
|
||||
// Recovered text goes straight to _onTerminalData(), never through xterm's
|
||||
// onData, so it is not counted as xterm's own (see connect()'s onData).
|
||||
// Created after terminal.open(): xterm's capture `input` listener on the
|
||||
// textarea is registered there, and must run before the controller's. No
|
||||
// device or mode gate, as in the primary pane: with a hardware keyboard it
|
||||
// costs one assignment per keydown. A failure leaves xterm's own handling.
|
||||
// textarea is registered there, and must run before the controller's.
|
||||
// create() returns null on a fine pointer (#716): the recovery is for soft
|
||||
// keyboards, and on a desktop it delivers a dead-key character twice.
|
||||
// A failure leaves xterm's own handling.
|
||||
_createKeyCode229Recovery() {
|
||||
this._destroyKeyCode229Recovery();
|
||||
if (!this.terminal) return;
|
||||
|
||||
@@ -2108,6 +2108,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
// Twin: TerminalTile (terminal-tile.js _createKeyCode229Recovery and its
|
||||
// connect() key handler and onData) wires its own controller the same way
|
||||
// for every grid tile and the split's Pane B; keep the two in step.
|
||||
// create() returns null unless the primary pointer is coarse (#716).
|
||||
try {
|
||||
this._keyCode229Recovery = window.CodemanKeyCode229Recovery?.create?.({
|
||||
textarea: this.terminal.textarea,
|
||||
|
||||
Reference in new issue
Block a user