feat(mobile): Send on Enter for the pinned CJK input field

A per-device setting next to CJK Input keeps typed text in the pinned
field until Enter instead of streaming it to the PTY, so a phone user can
scroll the terminal and edit an answer before sending (Termux-style).
One line goes as text + CR, several lines as one bracketed paste with a
delayed Enter, like the prompt composer. Shift+Enter is a newline,
Escape clears, Backspace on an empty field still reaches the PTY, and
autocorrect is on in this mode. The field grows with its text and the
keyboard layout reserves its real height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kamil KaliszandClaude Opus 5.5 committed 2026-11-15 18:38:25 +01:00
1 parent e99b42c387
commit e0e2f689cf
8 files changed
+307 -3

No files matched your search

+5
View File
@@ -4929,6 +4929,11 @@ class CodemanApp {
document.body.classList.toggle('cjk-input-visible', !!showCjk);
cjkEl.style.display = showCjk ? 'block' : 'none';
cjkEl.setAttribute('aria-hidden', showCjk ? 'false' : 'true');
if (typeof CjkInput !== 'undefined') {
CjkInput.setHoldUntilEnter?.(
!!(settings.cjkInputHoldUntilEnter ?? defaults.cjkInputHoldUntilEnter ?? false)
);
}
if (!showCjk) window.cjkActive = false;
if (typeof KeyboardHandler !== 'undefined') KeyboardHandler.updateLayoutForKeyboard();
}
+7
View File
@@ -2064,6 +2064,13 @@
</div>
<label class="switch switch-sm"><input type="checkbox" id="appSettingsCjkInput"><span class="slider"></span></label>
</div>
<div class="set-row" data-search="cjk input send on enter hold draft pinned prompt field phone">
<div class="set-row-text">
<span class="set-row-label">Input Field: Send on Enter</span>
<span class="set-row-desc">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.</span>
</div>
<label class="switch switch-sm"><input type="checkbox" id="appSettingsCjkHoldUntilEnter"><span class="slider"></span></label>
</div>
<div class="set-row" data-search="extended keyboard bar tab esc arrows phone">
<div class="set-row-text">
<span class="set-row-label">Extended Keyboard Bar <span class="set-tag">phone</span></span>
+76 -1
View File
@@ -57,6 +57,10 @@ const CjkInput = (() => {
let _dictationActive = false;
let _dictationDecayTimer = null;
let _printableKeydownAt = null;
// Send-on-Enter mode (setting cjkInputHoldUntilEnter): typed text stays in the
// 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;
const _listeners = {};
const PHANTOM = '​';
@@ -189,6 +193,12 @@ const CjkInput = (() => {
_t('flush SKIP composing');
return;
}
// Send-on-Enter: nothing leaves the field until Enter (keydown handler).
if (_hold) {
_t('flush SKIP hold');
_autoGrow();
return;
}
const val = _strip(_textarea.value);
_t(`flush ${val ? 'send len=' + val.length : 'empty'}`);
if (val) {
@@ -197,6 +207,35 @@ const CjkInput = (() => {
_resetToPhantom();
}
/** Send-on-Enter: grow the field with its content (up to the CSS max-height)
* and let the keyboard layout re-read its height. */
function _autoGrow() {
if (!_textarea) return;
const before = _textarea.style.height;
_textarea.style.height = 'auto';
_textarea.style.height = `${_textarea.scrollHeight}px`;
if (_textarea.style.height !== before && typeof KeyboardHandler !== 'undefined') {
KeyboardHandler.updateLayoutForKeyboard?.();
}
}
/** 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. */
function _sendHeld(val) {
if (!/\n/.test(val)) {
_send(val + '\r');
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);
}
/** Cancel any pending debounced flush */
function _cancelDebouncedFlush() {
if (_flushTimer) {
@@ -316,16 +355,25 @@ const CjkInput = (() => {
_t(`keydown ${_kdesc(e.key)} kc=${e.keyCode} ic=${e.isComposing} c=${_composing}`);
_printableKeydownAt = null;
if (e.key === 'Enter') {
// Send-on-Enter: Shift+Enter (or an IME still composing) is a newline
// in the field, never a send.
if (_hold && (e.shiftKey || e.isComposing || e.keyCode === 229)) {
setTimeout(_autoGrow, 0);
return;
}
e.preventDefault();
_composing = false;
_cancelDebouncedFlush();
const val = _strip(_textarea.value);
if (val) {
if (_hold && val) {
_sendHeld(val);
} else if (val) {
_send(val + '\r');
} else {
_send('\r');
}
_resetToPhantom();
if (_hold) _autoGrow();
return;
}
@@ -334,6 +382,7 @@ const CjkInput = (() => {
_composing = false;
_cancelDebouncedFlush();
_resetToPhantom();
if (_hold) _autoGrow();
return;
}
@@ -475,6 +524,32 @@ const CjkInput = (() => {
_resetToPhantom();
},
/**
* Send-on-Enter mode on or off (setting cjkInputHoldUntilEnter). On: text
* stays in the field until Enter and the browser's autocorrect is allowed,
* since nothing typed has reached the PTY yet. Off: the original live mode.
*/
setHoldUntilEnter(on) {
_hold = !!on;
if (!_textarea) return;
const v = _hold ? 'on' : 'off';
_textarea.setAttribute('autocorrect', v);
_textarea.setAttribute('autocapitalize', _hold ? 'sentences' : 'off');
_textarea.setAttribute('spellcheck', _hold ? 'true' : 'false');
_textarea.placeholder = _hold
? 'Type, Enter to send (Shift+Enter: new line, Esc: clear)'
: 'CJK input (Enter = send, Esc = clear)';
if (_hold) {
_cancelDebouncedFlush();
_autoGrow();
} else {
_textarea.style.height = '';
}
_t(`hold ${v}`);
},
get holdUntilEnter() { return _hold; },
/** Diagnostic: recent IME event trace (ring buffer). */
getTrace() {
return _trace.slice();
+5 -1
View File
@@ -455,7 +455,11 @@ const KeyboardHandler = {
caseSheet.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
}
if (main && keyboardHeight > 0) {
const cjkInputHeight = cjkInput?.classList.contains('cjk-input-visible') ? 44 : 0;
// The field grows with its text in Send-on-Enter mode, so reserve its
// real height (44 = the one-line field plus its border, the old constant).
const cjkInputHeight = cjkInput?.classList.contains('cjk-input-visible')
? Math.max(44, cjkInput.offsetHeight + 10)
: 0;
main.style.paddingBottom = `${84 + cjkInputHeight}px`;
}
} else if (keyboardHeight > 0) {
+6 -1
View File
@@ -649,6 +649,8 @@ Object.assign(CodemanApp.prototype, {
document.getElementById('appSettingsTerminalWheelLocal').checked =
settings.terminalWheelLocalScrollback ?? defaults.terminalWheelLocalScrollback ?? false;
document.getElementById('appSettingsCjkInput').checked = settings.cjkInputEnabled ?? defaults.cjkInputEnabled ?? false;
document.getElementById('appSettingsCjkHoldUntilEnter').checked =
settings.cjkInputHoldUntilEnter ?? defaults.cjkInputHoldUntilEnter ?? false;
document.getElementById('appSettingsExtendedKeyboardBar').checked = settings.extendedKeyboardBar ?? false;
document.getElementById('appSettingsTabTwoRows').checked = settings.tabTwoRows ?? defaults.tabTwoRows ?? false;
document.getElementById('appSettingsShowTabCliLogos').checked = this.tabCliLogosEnabled(settings);
@@ -3195,6 +3197,7 @@ Object.assign(CodemanApp.prototype, {
),
terminalWheelLocalScrollback: document.getElementById('appSettingsTerminalWheelLocal').checked,
cjkInputEnabled: document.getElementById('appSettingsCjkInput').checked,
cjkInputHoldUntilEnter: document.getElementById('appSettingsCjkHoldUntilEnter').checked,
webglRendererEnabled: document.getElementById('appSettingsWebglRenderer').checked,
extendedKeyboardBar: document.getElementById('appSettingsExtendedKeyboardBar').checked,
tabTwoRows: document.getElementById('appSettingsTabTwoRows').checked,
@@ -3440,6 +3443,7 @@ Object.assign(CodemanApp.prototype, {
// SettingsUpdateSchema (.strict()), so sending it would 400 the whole PUT.
keyboardHoldsRows: _khr,
cjkInputEnabled: _cjk,
cjkInputHoldUntilEnter: _cjkHold,
extendedKeyboardBar: _ekb,
skin: _skin,
language: _language,
@@ -4478,6 +4482,7 @@ Object.assign(CodemanApp.prototype, {
sessionListLayout: 'header',
sessionSidebarFontSize: 12,
cjkInputEnabled: false,
cjkInputHoldUntilEnter: false,
terminalWheelLocalScrollback: false, // mobile scrolls via touch, not wheel
webglRendererEnabled: false, // mobile always uses the DOM renderer
skin: 'daylight-blue',
@@ -5206,7 +5211,7 @@ Object.assign(CodemanApp.prototype, {
'showFontControls', 'showSystemStats', 'showGpuStats', 'showCpuMhz', 'headerStatsStyle', 'showTokenCount', 'showCost',
'showLifecycleLog', 'showResponseViewer', 'showRedrawButton',
'showMonitor', 'showProjectInsights', 'showFileBrowser', 'showSubagents',
'subagentActiveTabOnly', 'tabTwoRows', 'showTabCliLogos', 'tabOrientation', 'tabRailWidth', 'tabRailDetail', 'tabRailSort', 'tabArrangement', 'tabStateOrder', 'sessionListLayout', 'sessionSidebarFontSize', 'localEchoEnabled', 'keyboardHoldsRows', 'cjkInputEnabled', 'extendedKeyboardBar',
'subagentActiveTabOnly', 'tabTwoRows', 'showTabCliLogos', 'tabOrientation', 'tabRailWidth', 'tabRailDetail', 'tabRailSort', 'tabArrangement', 'tabStateOrder', 'sessionListLayout', 'sessionSidebarFontSize', 'localEchoEnabled', 'keyboardHoldsRows', 'cjkInputEnabled', 'cjkInputHoldUntilEnter', 'extendedKeyboardBar',
'skin', 'showPlanUsageLimits', 'showAttachmentsButton', 'showFileViewerButton', 'webglRendererEnabled',
'terminalFontFamily', 'terminalFontWeight', 'terminalFontWeightBold',
'language',