mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(mobile): Send on Enter second review fixes
- Never send a held answer as text + CR in one write: Codex folds an Enter in the same burst into a paste. A single character is typed, then CR ~120 ms later to the session captured at Enter; anything longer goes through _sendComposedPrompt. Drops HELD_DIRECT_MAX. No session keeps the text in the field. - Cap #cjkInput at 68px on every device, not only touch. - _autoGrow adds the border height and skips a hidden field. - setHoldUntilEnter returns early when the mode is unchanged. - Per-session held drafts: stashed on switch and tile focus, restored on return, dropped when the session is removed. - Toolbar Enter presses Enter in the visible CJK field (commits an active composition first). - Blank-only field sends a bare Enter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95fb147e9c
commit
64ee504247
10 files changed
+418
-92
No files matched your search
+13
-3
@@ -9438,10 +9438,15 @@ class CodemanApp {
|
||||
// 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.
|
||||
// switched, and the answer would be gone. On a real switch it is stashed for
|
||||
// the session being left (selectSession restores it on the way back), so a
|
||||
// stray swipe does not lose it. Live mode still clears, since a pending
|
||||
// debounced flush could fire mid-reconnect.
|
||||
if (typeof CjkInput !== 'undefined') {
|
||||
if (!(keepCjkDraft && CjkInput.holdUntilEnter)) CjkInput.clear();
|
||||
if (!(keepCjkDraft && CjkInput.holdUntilEnter)) {
|
||||
if (this.activeSessionId) CjkInput.stashDraft?.(this.activeSessionId);
|
||||
CjkInput.clear();
|
||||
}
|
||||
} else {
|
||||
const cjkEl = document.getElementById('cjkInput');
|
||||
if (cjkEl) cjkEl.value = '';
|
||||
@@ -9981,6 +9986,9 @@ class CodemanApp {
|
||||
if (this._tileGrid.has(sessionId)) return this._selectTiledSession(sessionId, options);
|
||||
if (options?.auto === true && !options?.leaveTiles) return;
|
||||
this.closeTileGrid({ keepStored: true, reselect: false });
|
||||
// The focused tile's Send on Enter draft: the null below hides that
|
||||
// session from _cleanupPreviousSession, which would clear it unstashed.
|
||||
if (typeof CjkInput !== 'undefined' && this.activeSessionId) CjkInput.stashDraft?.(this.activeSessionId);
|
||||
// The parked terminal still holds what it showed before the grid opened;
|
||||
// with no active id, the switch below snapshots none of it.
|
||||
this.activeSessionId = null;
|
||||
@@ -10039,6 +10047,7 @@ class CodemanApp {
|
||||
|
||||
this._cleanupPreviousSession(sessionId, { keepCjkDraft: reloadingSameSession });
|
||||
this.activeSessionId = sessionId;
|
||||
if (typeof CjkInput !== 'undefined') CjkInput.restoreDraft?.(sessionId);
|
||||
this._activateFileBrowserSession?.(sessionId);
|
||||
// A keyboard row hold belongs to the session it was taken for: release it here
|
||||
// if this one resizes instead (the geometry work below then fits it).
|
||||
@@ -10836,6 +10845,7 @@ class CodemanApp {
|
||||
this._flushedOffsets?.delete(sessionId);
|
||||
this._flushedTexts?.delete(sessionId);
|
||||
if (typeof KeyboardAccessoryBar !== 'undefined') KeyboardAccessoryBar.discardComposerDraft?.(sessionId);
|
||||
if (typeof CjkInput !== 'undefined') CjkInput.discardDraft?.(sessionId);
|
||||
// Drop any durably-queued input for a session that's actually gone (deleted/
|
||||
// exited). Not a lost prompt — the target no longer exists. Only reached on
|
||||
// real session removal, never on a tab switch.
|
||||
|
||||
+105
-36
@@ -65,9 +65,14 @@ const CjkInput = (() => {
|
||||
// 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).
|
||||
// Send-on-Enter: delivers a held answer, text first and Enter as a separate
|
||||
// delayed write, to the session it was typed for (terminal-ui.js).
|
||||
let _sendPrompt = null;
|
||||
// Send-on-Enter: whether setHoldUntilEnter() has applied the current mode to
|
||||
// the field yet, so a repeat call with the same mode leaves the field alone.
|
||||
let _holdApplied = false;
|
||||
// Send-on-Enter: held drafts of the sessions switched away from, by session id.
|
||||
const _drafts = new Map();
|
||||
const _listeners = {};
|
||||
|
||||
const PHANTOM = '';
|
||||
@@ -117,13 +122,6 @@ 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',
|
||||
@@ -227,28 +225,28 @@ const CjkInput = (() => {
|
||||
* and let the keyboard layout re-read its height. */
|
||||
function _autoGrow() {
|
||||
if (!_textarea) return;
|
||||
// A hidden field (no session shown yet) measures 0: leave the CSS height,
|
||||
// or it stays a sliver until the next keystroke.
|
||||
if (_textarea.getClientRects && !_textarea.getClientRects().length) {
|
||||
_textarea.style.height = '';
|
||||
return;
|
||||
}
|
||||
const before = _textarea.style.height;
|
||||
_textarea.style.height = 'auto';
|
||||
_textarea.style.height = `${_textarea.scrollHeight}px`;
|
||||
// border-box: scrollHeight leaves the borders out, offsetHeight - clientHeight adds them back.
|
||||
_textarea.style.height = `${_textarea.scrollHeight + _textarea.offsetHeight - _textarea.clientHeight}px`;
|
||||
if (_textarea.style.height !== before && typeof KeyboardHandler !== 'undefined') {
|
||||
KeyboardHandler.updateLayoutForKeyboard?.();
|
||||
}
|
||||
}
|
||||
|
||||
/** 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. */
|
||||
/** Send-on-Enter: deliver the held text, then Enter, through `_sendPrompt`
|
||||
* (terminal-ui.js _sendCjkPrompt). Enter is never part of the text's write:
|
||||
* Codex takes characters arriving in one burst as a paste and folds an Enter
|
||||
* inside it into the paste, and Claude Code does the same for a long burst, so
|
||||
* even `1\r` in one write sits unsent. Returns false when the text was refused
|
||||
* (too long, no session), so the field keeps it. */
|
||||
function _sendHeld(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;
|
||||
@@ -256,6 +254,30 @@ const CjkInput = (() => {
|
||||
return _sendPrompt(val) !== false;
|
||||
}
|
||||
|
||||
/** Enter: send what the field holds (or a bare Enter when it is empty) and
|
||||
* reset it. Returns false when a held answer was refused, which keeps it. */
|
||||
function _submit() {
|
||||
_composing = false;
|
||||
_cancelDebouncedFlush();
|
||||
clearTimeout(_compositionFlushTimer);
|
||||
_compositionFlushTimer = null;
|
||||
let val = _strip(_textarea.value);
|
||||
// Only blank lines held (Shift+Enter, then Enter): a bare Enter, not a
|
||||
// newline typed into the CLI.
|
||||
if (_hold && !val.trim()) val = '';
|
||||
if (_hold && val) {
|
||||
// Refused (too long, no session): keep the text so nothing is lost.
|
||||
if (!_sendHeld(val)) return false;
|
||||
} else if (val) {
|
||||
_send(val + '\r');
|
||||
} else {
|
||||
_send('\r');
|
||||
}
|
||||
_resetToPhantom();
|
||||
if (_hold) _autoGrow();
|
||||
return true;
|
||||
}
|
||||
|
||||
function _ctrlArmed() {
|
||||
return typeof KeyboardAccessoryBar !== 'undefined' && KeyboardAccessoryBar.isCtrlArmed?.() === true;
|
||||
}
|
||||
@@ -355,6 +377,7 @@ const CjkInput = (() => {
|
||||
_printableKeydownAt = null;
|
||||
_flushTimer = null;
|
||||
_textarea = document.getElementById('cjkInput');
|
||||
_holdApplied = false; // a new field has not had the mode applied
|
||||
if (!_textarea) return this;
|
||||
|
||||
_resetToPhantom();
|
||||
@@ -444,19 +467,7 @@ const CjkInput = (() => {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
_composing = false;
|
||||
_cancelDebouncedFlush();
|
||||
const val = _strip(_textarea.value);
|
||||
if (_hold && val) {
|
||||
// Refused (too long, no session): keep the text so nothing is lost.
|
||||
if (!_sendHeld(val)) return;
|
||||
} else if (val) {
|
||||
_send(val + '\r');
|
||||
} else {
|
||||
_send('\r');
|
||||
}
|
||||
_resetToPhantom();
|
||||
if (_hold) _autoGrow();
|
||||
_submit();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -618,8 +629,13 @@ const CjkInput = (() => {
|
||||
* since nothing typed has reached the PTY yet. Off: the original live mode.
|
||||
*/
|
||||
setHoldUntilEnter(on) {
|
||||
// Called on every session select and SSE reconnect: with the mode
|
||||
// unchanged, leave the field alone, since rewriting its attributes while
|
||||
// it has focus can disturb a composition in progress.
|
||||
if (_holdApplied && _textarea && _hold === !!on) return;
|
||||
_hold = !!on;
|
||||
if (!_textarea) return;
|
||||
_holdApplied = true;
|
||||
_heldBase = _strip(_textarea.value);
|
||||
const v = _hold ? 'on' : 'off';
|
||||
_textarea.setAttribute('autocorrect', v);
|
||||
@@ -639,6 +655,59 @@ const CjkInput = (() => {
|
||||
|
||||
get holdUntilEnter() { return _hold; },
|
||||
|
||||
/**
|
||||
* Enter from outside the field (the phone toolbar's Enter button, which
|
||||
* xterm's onData would swallow while the field is visible). Same as Enter
|
||||
* in the field. Returns false when nothing was done (not initialized) or a
|
||||
* held answer was refused.
|
||||
*/
|
||||
submit() {
|
||||
if (!_initialized || !_textarea) return false;
|
||||
_t(`submit (external) c=${_composing}`);
|
||||
if (_composing) {
|
||||
// An IME still composing (Gboard holds the current word, iOS the
|
||||
// unconverted pinyin): reading and resetting the field under it can
|
||||
// desync the keyboard. Blur commits the composition, focus keeps the
|
||||
// keyboard up (still inside the tap's gesture), then send what landed.
|
||||
_textarea.blur();
|
||||
_textarea.focus();
|
||||
}
|
||||
return _submit();
|
||||
},
|
||||
|
||||
/**
|
||||
* Send-on-Enter: keep the held draft of the session being left, so a
|
||||
* switch (a stray sideways swipe) does not lose an answer. Call before
|
||||
* clear(); restoreDraft() puts it back when that session is shown again.
|
||||
*/
|
||||
stashDraft(sessionId) {
|
||||
if (!_initialized || !_textarea || !_hold || !sessionId) return;
|
||||
// An empty field leaves any stash alone: a draft only sits in the map
|
||||
// while its session is not shown (restoreDraft takes it out), and the
|
||||
// tile grid may stash an id whose draft is already put away.
|
||||
const draft = _strip(_textarea.value);
|
||||
if (draft.trim()) _drafts.set(sessionId, draft);
|
||||
},
|
||||
|
||||
/** Send-on-Enter: show the draft stashed for this session, if any, unless
|
||||
* the field already holds text. */
|
||||
restoreDraft(sessionId) {
|
||||
if (!_initialized || !_textarea || !_hold || !_drafts.has(sessionId)) return;
|
||||
if (_strip(_textarea.value)) return;
|
||||
const draft = _drafts.get(sessionId);
|
||||
_drafts.delete(sessionId);
|
||||
_t(`restore draft len=${draft.length}`);
|
||||
_textarea.value = PHANTOM + draft;
|
||||
_textarea.setSelectionRange(_textarea.value.length, _textarea.value.length);
|
||||
_heldBase = draft;
|
||||
_autoGrow();
|
||||
},
|
||||
|
||||
/** Forget a stashed draft when its session no longer exists. */
|
||||
discardDraft(sessionId) {
|
||||
_drafts.delete(sessionId);
|
||||
},
|
||||
|
||||
/** Diagnostic: recent IME event trace (ring buffer). */
|
||||
getTrace() {
|
||||
return _trace.slice();
|
||||
|
||||
@@ -2082,6 +2082,16 @@ Object.assign(CodemanApp.prototype, {
|
||||
* so overlay flush, flushed-offset cleanup and ordering are all reused. */
|
||||
sendEnterKey() {
|
||||
if (!this.activeSessionId) return;
|
||||
// While the CJK field is visible, onData drops everything (cjkActive), this
|
||||
// Enter included. Press Enter in the field instead: it sends what the field
|
||||
// holds (a Send on Enter answer, or live text not yet flushed), then Enter.
|
||||
if (
|
||||
typeof CjkInput !== 'undefined' &&
|
||||
document.getElementById('cjkInput')?.classList.contains('cjk-input-visible')
|
||||
) {
|
||||
CjkInput.submit?.();
|
||||
return;
|
||||
}
|
||||
const coreService = this.terminal?._core?.coreService;
|
||||
if (coreService && typeof coreService.triggerDataEvent === 'function') {
|
||||
coreService.triggerDataEvent('\r', true);
|
||||
|
||||
@@ -14199,6 +14199,11 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat
|
||||
resize: none;
|
||||
line-height: 1.4;
|
||||
box-sizing: border-box;
|
||||
/* Send on Enter grows the field with its text (input-cjk.js _autoGrow), and the
|
||||
setting is not limited to phones: cap it everywhere, not only in the
|
||||
.touch-device rule, or on desktop it pushes the terminal (and its PTY) down. */
|
||||
max-height: 68px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#cjkInput:focus {
|
||||
|
||||
@@ -4570,11 +4570,15 @@ Object.assign(CodemanApp.prototype, {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* answer, then Enter as its own write ~120 ms later. Never `<text>\r` in one
|
||||
* write: Codex reads characters arriving in one burst as a paste and folds an
|
||||
* Enter inside it into the paste (even `1\r` stays unsent), and Claude Code
|
||||
* does the same for a long burst. Same split as TmuxManager.sendInput: a
|
||||
* single character is typed (a selection dialog ignores a pasted `3`, then
|
||||
* Enter confirms the highlighted option), anything else goes through the
|
||||
* composer's path as one bracketed paste. The session is captured now, so the
|
||||
* delayed Enter cannot follow a tab switch. Returns false when nothing was
|
||||
* sent (no session, too long), so the field keeps the text.
|
||||
*/
|
||||
_sendCjkPrompt(text) {
|
||||
const sessionId = this.activeSessionId;
|
||||
@@ -4582,10 +4586,17 @@ Object.assign(CodemanApp.prototype, {
|
||||
_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.
|
||||
// A held answer is never what an armed one-shot Ctrl applies to (CjkInput
|
||||
// sends the next typed character straight away as the control key), so
|
||||
// Enter spends it, the same rule _handleCjkInput has for a longer chunk.
|
||||
KeyboardAccessoryBar.clearCtrl?.();
|
||||
_crashDiag.log(`CJK prompt→${sessionId.slice(0, 8)} len=${text.length}`);
|
||||
if ([...text].length === 1) {
|
||||
if (this._localEchoPolicy === 'predict') this._predictiveEcho?.clearPredictions();
|
||||
this._sendInputAsync(sessionId, text);
|
||||
setTimeout(() => this._sendInputAsync(sessionId, '\r', { useMux: true }), 120);
|
||||
return true;
|
||||
}
|
||||
return KeyboardAccessoryBar._sendComposedPrompt(sessionId, text);
|
||||
},
|
||||
|
||||
|
||||
@@ -2651,6 +2651,17 @@ Object.assign(CodemanApp.prototype, {
|
||||
// Aborts any in-flight normal select at its next _isStaleSelect check.
|
||||
const selectGen = ++this._selectGeneration;
|
||||
this._hideWebviewLayer?.();
|
||||
// The one CJK field follows tile focus, and Enter sends to the session
|
||||
// active at that moment: a Send on Enter draft typed for one tile must not
|
||||
// go to the next. Stash it for the tile left, show the one focused (also
|
||||
// the draft openTileGrid's cleanup stashed for the session it parked).
|
||||
if (typeof CjkInput !== 'undefined') {
|
||||
if (this.activeSessionId && this.activeSessionId !== sessionId) {
|
||||
CjkInput.stashDraft?.(this.activeSessionId);
|
||||
CjkInput.clear();
|
||||
}
|
||||
CjkInput.restoreDraft?.(sessionId);
|
||||
}
|
||||
this.activeSessionId = sessionId;
|
||||
grid.focusedId = sessionId;
|
||||
// Moving focus off a zoomed tile restores the grid, as selecting another
|
||||
|
||||
Reference in new issue
Block a user