mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(mobile): Send on Enter review fixes
- A long single line (over 64 characters) or several lines now go through the composer's _sendComposedPrompt: one bracketed paste, then Enter as a separate delayed write to the session captured at Enter. Claude Code took a long `<text>\r` burst as a paste and left it unsent, and the old delayed Enter followed a tab switch. A refused prompt keeps the text in the field. - Deleting held text no longer sends Backspace to the PTY. It goes out only when the field was already empty (the phantom itself deleted), so select-all + delete is covered too. - With the one-shot Ctrl armed, the next single typed character skips the hold and reaches _handleCjkInput, which turns it into the control byte; any other change spends the modifier, as in live mode. - A reload of the session already shown (tapping its tab, the geometry retry) keeps a held draft. - With the keyboard down the field stays one line tall, so it no longer covers the terminal's last rows. - zh-CN strings for both field placeholders, and a test pinning cjkInputHoldUntilEnter as per-device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8a4466643
commit
95fb147e9c
9 files changed
+474
-33
No files matched your search
+11
-3
@@ -9384,7 +9384,7 @@ class CodemanApp {
|
||||
|
||||
// `skipSnapshot`: the tile grid opening on the session it parks
|
||||
// (tile-grid.js openTileGrid), whose snapshot closing the grid discards.
|
||||
_cleanupPreviousSession(newSessionId, { skipSnapshot = false } = {}) {
|
||||
_cleanupPreviousSession(newSessionId, { skipSnapshot = false, keepCjkDraft = false } = {}) {
|
||||
// Snapshot the OUTGOING session's xterm rendered state (viewport + scrollback +
|
||||
// colors/attrs) before the terminal gets cleared/reset. Lets us restore the
|
||||
// exact view on switch-back rather than replaying codex's byte stream, which
|
||||
@@ -9437,8 +9437,11 @@ class CodemanApp {
|
||||
// Clear CJK input to prevent sending stale text to the wrong session.
|
||||
// Must go through CjkInput.clear() — a raw value wipe leaves the module's
|
||||
// pending flush timers armed and drops the phantom char it relies on.
|
||||
// A held Send on Enter draft survives a reload of the same session: nothing
|
||||
// switched, and the answer would be gone. Live mode still clears, since a
|
||||
// pending debounced flush could fire mid-reconnect.
|
||||
if (typeof CjkInput !== 'undefined') {
|
||||
CjkInput.clear();
|
||||
if (!(keepCjkDraft && CjkInput.holdUntilEnter)) CjkInput.clear();
|
||||
} else {
|
||||
const cjkEl = document.getElementById('cjkInput');
|
||||
if (cjkEl) cjkEl.value = '';
|
||||
@@ -9982,7 +9985,12 @@ class CodemanApp {
|
||||
// with no active id, the switch below snapshots none of it.
|
||||
this.activeSessionId = null;
|
||||
}
|
||||
// A reload of the session already shown (tapping its own tab, the geometry
|
||||
// retry) is not a switch: _cleanupPreviousSession keeps a Send on Enter
|
||||
// draft for it, which it cannot tell on its own once activeSessionId is null.
|
||||
let reloadingSameSession = false;
|
||||
if (this.activeSessionId === sessionId && forceReload) {
|
||||
reloadingSameSession = true;
|
||||
this.terminalBufferCache?.delete(sessionId);
|
||||
this._xtermSnapshots?.delete(sessionId);
|
||||
try { localStorage.removeItem(`codeman-xs-${sessionId}`); } catch {}
|
||||
@@ -10029,7 +10037,7 @@ class CodemanApp {
|
||||
// A session tab takes the stage back from any active web tab.
|
||||
this._hideWebviewLayer?.();
|
||||
|
||||
this._cleanupPreviousSession(sessionId);
|
||||
this._cleanupPreviousSession(sessionId, { keepCjkDraft: reloadingSameSession });
|
||||
this.activeSessionId = sessionId;
|
||||
this._activateFileBrowserSession?.(sessionId);
|
||||
// A keyboard row hold belongs to the session it was taken for: release it here
|
||||
|
||||
@@ -744,6 +744,8 @@
|
||||
'对于本地 Claude 会话,打开屏幕键盘时会保持会话尺寸并改为滚动视图,这样 Claude 不会重绘屏幕而丢失对话记录行。全屏界面(Codex、Claude 的全屏模式)仍像以前一样调整尺寸。',
|
||||
'CJK Input': '中日韩输入',
|
||||
'Input Field: Send on Enter': '输入框:按 Enter 发送',
|
||||
'CJK input (Enter = send, Esc = clear)': '中日韩输入(Enter 发送,Esc 清除)',
|
||||
'Type, Enter to send (Shift+Enter: new line, Esc: clear)': '输入文字,按 Enter 发送(Shift+Enter 换行,Esc 清除)',
|
||||
'With CJK Input on, keep typed text in the field until Enter instead of sending it as you type, so you can scroll the terminal and edit before sending. Autocorrect is on in this mode.':
|
||||
'开启中日韩输入后,输入的文字会保留在输入框中,直到按下 Enter 才发送,而不是边输入边发送,这样可以先滚动终端、编辑后再发送。此模式下会开启自动更正。',
|
||||
'Extended Keyboard Bar': '扩展键盘栏',
|
||||
|
||||
+102
-13
@@ -61,6 +61,13 @@ const CjkInput = (() => {
|
||||
// field until Enter, like a chat box, instead of streaming to the PTY as it is
|
||||
// typed. Lets a phone user scroll the terminal and edit an answer before sending.
|
||||
let _hold = false;
|
||||
// Send-on-Enter: the held text as of the last settled input event (phantom
|
||||
// stripped). Tells a deletion that emptied the field from a Backspace on a field
|
||||
// that was already empty, and finds the one character an armed Ctrl applies to.
|
||||
let _heldBase = '';
|
||||
// Send-on-Enter: delivers a held prompt that is long or multi-line to the
|
||||
// session it was typed for (terminal-ui.js passes the composer's send path).
|
||||
let _sendPrompt = null;
|
||||
const _listeners = {};
|
||||
|
||||
const PHANTOM = '';
|
||||
@@ -110,6 +117,13 @@ const CjkInput = (() => {
|
||||
const DEBOUNCE_DICTATION_MS = 1500;
|
||||
const DICTATION_DECAY_MS = 3000;
|
||||
|
||||
// Send-on-Enter: the longest single line still written as `<text>\r` in one
|
||||
// go. Claude Code takes a burst of about a hundred characters or more as a
|
||||
// paste (src/web/route-helpers.ts) and turns its \r into a newline, so the
|
||||
// answer would sit unsent. Short answers (a menu digit, a word) keep the
|
||||
// one-write form; anything longer goes out as a prompt with a separate Enter.
|
||||
const HELD_DIRECT_MAX = 64;
|
||||
|
||||
const PASSTHROUGH_KEYS = {
|
||||
ArrowUp: '\x1b[A',
|
||||
ArrowDown: '\x1b[B',
|
||||
@@ -164,6 +178,7 @@ const CjkInput = (() => {
|
||||
}
|
||||
|
||||
function _resetToPhantom() {
|
||||
_heldBase = '';
|
||||
// Skip redundant writes: every programmatic value/selection mutation can
|
||||
// desync an Android IME's input session (InputConnection) — after which
|
||||
// the keyboard composes in its own UI but NO events ever reach the page.
|
||||
@@ -196,6 +211,7 @@ const CjkInput = (() => {
|
||||
// Send-on-Enter: nothing leaves the field until Enter (keydown handler).
|
||||
if (_hold) {
|
||||
_t('flush SKIP hold');
|
||||
_holdSettle();
|
||||
_autoGrow();
|
||||
return;
|
||||
}
|
||||
@@ -219,21 +235,86 @@ const CjkInput = (() => {
|
||||
}
|
||||
}
|
||||
|
||||
/** Send-on-Enter: deliver the held text as one prompt, then Enter. One line
|
||||
* goes as typed text + CR in one write (what live mode's Enter sends, so CLI
|
||||
* menus that answer to a digit keep working). Several lines go as one
|
||||
* bracketed paste with Enter as a separate, delayed write, the same bytes as
|
||||
* the mobile prompt composer (keyboard-accessory.js _sendComposedPrompt), so
|
||||
* embedded newlines don't submit early. */
|
||||
/** Send-on-Enter: deliver the held text, then Enter. Returns false when the
|
||||
* text was refused (too long, no session), so the field keeps it.
|
||||
* A short single line goes as typed text + CR in one write: what live mode's
|
||||
* Enter sends, so CLI menus that answer to a digit keep working. Anything
|
||||
* longer, or with several lines, goes through `_sendPrompt`: the mobile prompt
|
||||
* composer's path (KeyboardAccessoryBar._sendComposedPrompt), one bracketed
|
||||
* paste and then Enter as a separate, delayed write bound to the session the
|
||||
* text was typed for, so neither a long line nor an embedded newline submits
|
||||
* early and a tab switch cannot take the Enter elsewhere. */
|
||||
function _sendHeld(val) {
|
||||
if (!/\n/.test(val)) {
|
||||
if (!/\n/.test(val) && val.length <= HELD_DIRECT_MAX) {
|
||||
_send(val + '\r');
|
||||
return true;
|
||||
}
|
||||
if (!_sendPrompt) {
|
||||
_t('hold send DROP no-prompt-path');
|
||||
return false;
|
||||
}
|
||||
return _sendPrompt(val) !== false;
|
||||
}
|
||||
|
||||
function _ctrlArmed() {
|
||||
return typeof KeyboardAccessoryBar !== 'undefined' && KeyboardAccessoryBar.isCtrlArmed?.() === true;
|
||||
}
|
||||
|
||||
/** Index of the one character `after` adds to `before`, or -1 when the change
|
||||
* is anything else (several characters, a deletion, a rewrite). */
|
||||
function _singleInsertionAt(before, after) {
|
||||
if (after.length !== before.length + 1) return -1;
|
||||
let i = 0;
|
||||
while (i < before.length && before[i] === after[i]) i++;
|
||||
return after.slice(i + 1) === before.slice(i) ? i : -1;
|
||||
}
|
||||
|
||||
/** Send-on-Enter: settle the field after an input event. With the shell bar's
|
||||
* one-shot Ctrl armed, a single typed character is not held: it leaves the
|
||||
* field and goes to the PTY, where _handleCjkInput turns it into the control
|
||||
* byte (`c` → Ctrl+C). Any other change spends the modifier, the same rule
|
||||
* live mode follows for a multi-character chunk. */
|
||||
function _holdSettle() {
|
||||
const before = _heldBase;
|
||||
const now = _strip(_textarea.value);
|
||||
_heldBase = now;
|
||||
if (now === before || !_ctrlArmed()) return;
|
||||
const at = _singleInsertionAt(before, now);
|
||||
if (at < 0 || now[at] === '\n') {
|
||||
KeyboardAccessoryBar.clearCtrl?.();
|
||||
return;
|
||||
}
|
||||
let text = val;
|
||||
while (/\x1b\[20[01]~/.test(text)) text = text.replace(/\x1b\[20[01]~/g, '');
|
||||
_send(`\x1b[200~${text.replace(/\r?\n/g, '\r')}\x1b[201~`);
|
||||
setTimeout(() => _send('\r'), 120);
|
||||
_t('hold ctrl key');
|
||||
_textarea.value = PHANTOM + before;
|
||||
_textarea.setSelectionRange(1 + at, 1 + at);
|
||||
_heldBase = before;
|
||||
_send(now[at]);
|
||||
}
|
||||
|
||||
/** Send-on-Enter input handling: nothing is flushed, the field only settles.
|
||||
* A deletion forwards Backspace to the PTY only when the field was ALREADY
|
||||
* empty, i.e. the phantom itself was deleted. Deleting the last held
|
||||
* character (or select-all + delete) must not also delete a character from
|
||||
* the CLI's own composer, which Attach, image paste, Path and the mic fill. */
|
||||
function _holdInput(e) {
|
||||
if (_composing) return; // composed text settles at compositionend (_flush)
|
||||
if (e.inputType === 'deleteContentBackward' || e.inputType === 'deleteWordBackward') {
|
||||
const wasEmpty = !_heldBase;
|
||||
_heldBase = _strip(_textarea.value);
|
||||
if (!_heldBase) {
|
||||
if (wasEmpty) _send('\x7f');
|
||||
_resetToPhantom();
|
||||
} else if (!_textarea.value.startsWith(PHANTOM)) {
|
||||
// Backspace at the very start of the text deleted the phantom: put it
|
||||
// back with the caret where it was, at the start of the text.
|
||||
_textarea.value = PHANTOM + _textarea.value;
|
||||
_textarea.setSelectionRange(1, 1);
|
||||
}
|
||||
_autoGrow();
|
||||
return;
|
||||
}
|
||||
_holdSettle();
|
||||
_autoGrow();
|
||||
}
|
||||
|
||||
/** Cancel any pending debounced flush */
|
||||
@@ -265,10 +346,11 @@ const CjkInput = (() => {
|
||||
}
|
||||
|
||||
return {
|
||||
init({ send }) {
|
||||
init({ send, sendPrompt = null }) {
|
||||
if (_initialized) this.destroy();
|
||||
|
||||
_send = send;
|
||||
_sendPrompt = sendPrompt;
|
||||
_composing = false;
|
||||
_printableKeydownAt = null;
|
||||
_flushTimer = null;
|
||||
@@ -366,7 +448,8 @@ const CjkInput = (() => {
|
||||
_cancelDebouncedFlush();
|
||||
const val = _strip(_textarea.value);
|
||||
if (_hold && val) {
|
||||
_sendHeld(val);
|
||||
// Refused (too long, no session): keep the text so nothing is lost.
|
||||
if (!_sendHeld(val)) return;
|
||||
} else if (val) {
|
||||
_send(val + '\r');
|
||||
} else {
|
||||
@@ -454,6 +537,11 @@ const CjkInput = (() => {
|
||||
_composing = false;
|
||||
}
|
||||
|
||||
if (_hold) {
|
||||
_holdInput(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// ── Backspace / delete detection ──
|
||||
if (e.inputType === 'deleteContentBackward' || e.inputType === 'deleteWordBackward') {
|
||||
if (_composing) return;
|
||||
@@ -532,6 +620,7 @@ const CjkInput = (() => {
|
||||
setHoldUntilEnter(on) {
|
||||
_hold = !!on;
|
||||
if (!_textarea) return;
|
||||
_heldBase = _strip(_textarea.value);
|
||||
const v = _hold ? 'on' : 'off';
|
||||
_textarea.setAttribute('autocorrect', v);
|
||||
_textarea.setAttribute('autocapitalize', _hold ? 'sentences' : 'off');
|
||||
|
||||
@@ -14235,6 +14235,13 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat
|
||||
bottom: calc(var(--safe-area-bottom) + 84px);
|
||||
}
|
||||
|
||||
/* Send on Enter grows the field with its text, but with the keyboard down .main
|
||||
reserves a fixed 84px (below), so a grown field would cover the terminal's
|
||||
last rows. Keep it one line tall there; the text scrolls inside. */
|
||||
.touch-device:not(.keyboard-visible) #cjkInput.cjk-input-visible {
|
||||
max-height: 34px;
|
||||
}
|
||||
|
||||
body.touch-device.cjk-input-visible .main {
|
||||
padding-bottom: calc(84px + var(--safe-area-bottom));
|
||||
}
|
||||
|
||||
@@ -1083,6 +1083,10 @@ Object.assign(CodemanApp.prototype, {
|
||||
send: (text) => {
|
||||
this._handleCjkInput(text);
|
||||
},
|
||||
// Send on Enter: a long or multi-line held answer goes out like the
|
||||
// mobile prompt composer's Send (one bracketed paste, then Enter as a
|
||||
// separate delayed write), bound to the session it was typed for.
|
||||
sendPrompt: (text) => this._sendCjkPrompt(text),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4564,6 +4568,27 @@ Object.assign(CodemanApp.prototype, {
|
||||
this._sendInputAsync(this.activeSessionId, text);
|
||||
},
|
||||
|
||||
/**
|
||||
* Send on Enter (CjkInput, setting cjkInputHoldUntilEnter): deliver a held
|
||||
* answer that is too long for one `<text>\r` write, or has several lines.
|
||||
* Claude Code takes a long burst as a paste and its \r as a newline, so it goes
|
||||
* through the composer's path instead: the session is captured now, so the
|
||||
* delayed Enter cannot follow a tab switch, and the length check applies.
|
||||
* Returns false when nothing was sent, so the field keeps the text.
|
||||
*/
|
||||
_sendCjkPrompt(text) {
|
||||
const sessionId = this.activeSessionId;
|
||||
if (!sessionId || typeof KeyboardAccessoryBar === 'undefined') {
|
||||
_crashDiag.log(`CJK prompt DROP no-session len=${text.length}`);
|
||||
return false;
|
||||
}
|
||||
// A multi-character chunk spends an armed one-shot Ctrl (same rule as
|
||||
// _handleCjkInput); leaving it armed would modify the next keystroke.
|
||||
KeyboardAccessoryBar.clearCtrl?.();
|
||||
_crashDiag.log(`CJK prompt→${sessionId.slice(0, 8)} len=${text.length}`);
|
||||
return KeyboardAccessoryBar._sendComposedPrompt(sessionId, text);
|
||||
},
|
||||
|
||||
/**
|
||||
* Re-assert a history anchor captured before a terminal write (#358).
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user