diff --git a/.changeset/cjk-send-on-enter.md b/.changeset/cjk-send-on-enter.md
new file mode 100644
index 00000000..9241ef1f
--- /dev/null
+++ b/.changeset/cjk-send-on-enter.md
@@ -0,0 +1,5 @@
+---
+"aicodeman": patch
+---
+
+Add a per-device "Send on Enter" mode for the pinned CJK input field, so phone users can scroll the terminal while a typed answer waits in the field until Enter.
diff --git a/docs/wiki/Settings-Reference.md b/docs/wiki/Settings-Reference.md
index 821d6ab0..99d00430 100644
--- a/docs/wiki/Settings-Reference.md
+++ b/docs/wiki/Settings-Reference.md
@@ -48,6 +48,7 @@ non-updatable. See [Running As A Service](Running-As-A-Service).
| Local Echo | On for touch devices | Paints keystrokes locally and flushes on Enter. See [Input And Voice](Input-And-Voice). |
| Keep Size Under Keyboard | On | For local Claude sessions, the on-screen keyboard no longer resizes the session: the terminal keeps its rows and the view scrolls so the prompt sits just above the keyboard. Resizing made Claude reprint its screen and drop transcript lines from history. Codex, Claude's fullscreen mode, remote and Docker sessions resize as before. See [Mobile Guide](Mobile-Guide). |
| CJK Input | Off | IME composition through a dedicated text field. |
+| Input Field: Send on Enter | Off | With CJK Input on, typed text stays in the pinned field until Enter instead of streaming to the CLI, so on a phone you can scroll the terminal and edit an answer first. Shift+Enter adds a line, Esc clears, autocorrect is on. |
| Extended Keyboard Bar | Per device | Which accessory bar phones get. Shell sessions override it while they are active. |
| Wheel Scrolls Local History | Off | Keeps the wheel on the local buffer instead of forwarding it to the CLI. Fullscreen pi leaves that buffer empty and has no paging fallback, so with this on the wheel does nothing there. |
| Auto Copy Selection | Off | Copies highlighted terminal text to the clipboard the moment you finish selecting it. Ctrl+C still copies on demand. |
diff --git a/src/web/public/app.js b/src/web/public/app.js
index e2b4c68c..1f178c2a 100644
--- a/src/web/public/app.js
+++ b/src/web/public/app.js
@@ -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();
}
diff --git a/src/web/public/index.html b/src/web/public/index.html
index 7d1d1430..4ce3de8b 100644
--- a/src/web/public/index.html
+++ b/src/web/public/index.html
@@ -2064,6 +2064,13 @@
+
+
+ Input Field: Send on Enter
+ 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.
+
+
+
Extended Keyboard Bar phone
diff --git a/src/web/public/input-cjk.js b/src/web/public/input-cjk.js
index 4f5420b7..89d7cccd 100644
--- a/src/web/public/input-cjk.js
+++ b/src/web/public/input-cjk.js
@@ -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();
diff --git a/src/web/public/mobile-handlers.js b/src/web/public/mobile-handlers.js
index e172683e..8e008dcd 100644
--- a/src/web/public/mobile-handlers.js
+++ b/src/web/public/mobile-handlers.js
@@ -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) {
diff --git a/src/web/public/settings-ui.js b/src/web/public/settings-ui.js
index 8cd7a874..8a9f9c76 100644
--- a/src/web/public/settings-ui.js
+++ b/src/web/public/settings-ui.js
@@ -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',
diff --git a/test/input-cjk-hold.test.ts b/test/input-cjk-hold.test.ts
new file mode 100644
index 00000000..5d59349c
--- /dev/null
+++ b/test/input-cjk-hold.test.ts
@@ -0,0 +1,202 @@
+/**
+ * @fileoverview Send-on-Enter mode of the CJK input field (input-cjk.js,
+ * setting cjkInputHoldUntilEnter): typed text stays in the field until Enter,
+ * so a phone user can scroll the terminal and edit an answer before sending.
+ *
+ * Same vm-sandbox approach as input-cjk.test.ts, with a stub textarea that also
+ * carries the attributes and style the mode touches.
+ */
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+import vm from 'node:vm';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const PHANTOM = '';
+
+function makeTextarea() {
+ const listeners = new Map void>>();
+ const attrs: Record = {};
+ return {
+ value: '',
+ placeholder: '',
+ style: { height: '' } as Record,
+ scrollHeight: 34,
+ attrs,
+ blur: () => {},
+ focus: () => {},
+ classList: { contains: (c: string) => c === 'cjk-input-visible' },
+ setSelectionRange: () => {},
+ setAttribute: (k: string, v: string) => {
+ attrs[k] = v;
+ },
+ addEventListener: (ev: string, fn: (e?: unknown) => void) => {
+ listeners.set(ev, [...(listeners.get(ev) ?? []), fn]);
+ },
+ removeEventListener: (ev: string, fn: (e?: unknown) => void) => {
+ listeners.set(
+ ev,
+ (listeners.get(ev) ?? []).filter((f) => f !== fn)
+ );
+ },
+ fire(ev: string, arg: Record = {}) {
+ const base = { preventDefault: () => {}, stopPropagation: () => {}, ...arg };
+ for (const fn of listeners.get(ev) ?? []) fn(base);
+ },
+ };
+}
+
+function load({ hold = true } = {}) {
+ const textarea = makeTextarea();
+ const sent: string[] = [];
+ const layout = vi.fn();
+ const context = vm.createContext({
+ window: {},
+ document: { getElementById: (id: string) => (id === 'cjkInput' ? textarea : null), activeElement: null },
+ navigator: { userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X)' },
+ KeyboardHandler: { updateLayoutForKeyboard: layout },
+ setTimeout: (fn: () => void, ms?: number) => setTimeout(fn, ms),
+ clearTimeout: (t: ReturnType) => clearTimeout(t),
+ performance: { now: () => performance.now() },
+ console,
+ });
+ const src = readFileSync(resolve(import.meta.dirname, '../src/web/public/input-cjk.js'), 'utf8');
+ vm.runInContext(src, context, { filename: 'input-cjk.js' });
+ const CjkInput = vm.runInContext('CjkInput', context);
+ CjkInput.init({ send: (t: string) => sent.push(t) });
+ CjkInput.setHoldUntilEnter(hold);
+ textarea.fire('focus');
+ return { CjkInput, textarea, sent, layout };
+}
+
+function type(textarea: ReturnType, text: string) {
+ textarea.value = PHANTOM + text;
+ textarea.fire('input', { isComposing: false, inputType: 'insertText' });
+}
+
+describe('CJK input: Send on Enter', () => {
+ beforeEach(() => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date', 'performance'] });
+ });
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it('keeps typed text in the field instead of streaming it', () => {
+ const { textarea, sent } = load();
+ type(textarea, 'use Postgres');
+ vi.advanceTimersByTime(5000);
+ expect(sent).toEqual([]);
+ expect(textarea.value).toBe(PHANTOM + 'use Postgres');
+ });
+
+ it('keeps text after a physical keystroke (no zero-latency flush)', () => {
+ const { textarea, sent } = load();
+ textarea.fire('keydown', { key: 'a', keyCode: 65, ctrlKey: false, altKey: false, metaKey: false });
+ type(textarea, 'a');
+ vi.advanceTimersByTime(1000);
+ expect(sent).toEqual([]);
+ });
+
+ it('keeps text across a composition cycle and autocorrect rewrites', () => {
+ const { textarea, sent } = load();
+ textarea.fire('compositionstart');
+ textarea.value = PHANTOM + 'teh';
+ textarea.fire('input', { isComposing: true, inputType: 'insertCompositionText' });
+ textarea.fire('compositionend');
+ textarea.value = PHANTOM + 'the';
+ textarea.fire('input', { isComposing: false, inputType: 'insertReplacementText' });
+ vi.advanceTimersByTime(5000);
+ expect(sent).toEqual([]);
+ expect(textarea.value).toBe(PHANTOM + 'the');
+ });
+
+ it('sends one line as text + CR on Enter, then clears the field', () => {
+ const { textarea, sent } = load();
+ type(textarea, 'yes, use Postgres');
+ const preventDefault = vi.fn();
+ textarea.fire('keydown', { key: 'Enter', keyCode: 13, shiftKey: false, preventDefault });
+ expect(preventDefault).toHaveBeenCalled();
+ expect(sent).toEqual(['yes, use Postgres\r']);
+ expect(textarea.value).toBe(PHANTOM);
+ });
+
+ it('sends a digit as typed so CLI menus still answer to it', () => {
+ const { textarea, sent } = load();
+ type(textarea, '2');
+ textarea.fire('keydown', { key: 'Enter', keyCode: 13, shiftKey: false });
+ expect(sent).toEqual(['2\r']);
+ });
+
+ it('sends several lines as one bracketed paste, Enter as a later write', () => {
+ const { textarea, sent } = load();
+ type(textarea, 'line one\nline two');
+ textarea.fire('keydown', { key: 'Enter', keyCode: 13, shiftKey: false });
+ expect(sent).toEqual(['\x1b[200~line one\rline two\x1b[201~']);
+ vi.advanceTimersByTime(150);
+ expect(sent).toEqual(['\x1b[200~line one\rline two\x1b[201~', '\r']);
+ });
+
+ it('drops paste markers inside the held text', () => {
+ const { textarea, sent } = load();
+ type(textarea, 'a\x1b[201~b\nc');
+ textarea.fire('keydown', { key: 'Enter', keyCode: 13, shiftKey: false });
+ expect(sent[0]).toBe('\x1b[200~ab\rc\x1b[201~');
+ });
+
+ it('treats Shift+Enter as a newline, never a send', () => {
+ const { textarea, sent } = load();
+ type(textarea, 'first');
+ const preventDefault = vi.fn();
+ textarea.fire('keydown', { key: 'Enter', keyCode: 13, shiftKey: true, preventDefault });
+ vi.advanceTimersByTime(10);
+ expect(preventDefault).not.toHaveBeenCalled();
+ expect(sent).toEqual([]);
+ });
+
+ it('sends a bare Enter when the field is empty (accepting a default answer)', () => {
+ const { textarea, sent } = load();
+ textarea.fire('keydown', { key: 'Enter', keyCode: 13, shiftKey: false });
+ expect(sent).toEqual(['\r']);
+ });
+
+ it('still forwards Backspace on an empty field to the PTY', () => {
+ const { textarea, sent } = load();
+ textarea.fire('keydown', { key: 'Backspace', keyCode: 8 });
+ expect(sent).toEqual(['\x7f']);
+ });
+
+ it('Escape clears the held text without sending', () => {
+ const { textarea, sent } = load();
+ type(textarea, 'never mind');
+ textarea.fire('keydown', { key: 'Escape', keyCode: 27 });
+ expect(sent).toEqual([]);
+ expect(textarea.value).toBe(PHANTOM);
+ });
+
+ it('turns autocorrect on in the mode and back off without it', () => {
+ const { CjkInput, textarea } = load();
+ expect(textarea.attrs.autocorrect).toBe('on');
+ expect(textarea.attrs.spellcheck).toBe('true');
+ CjkInput.setHoldUntilEnter(false);
+ expect(textarea.attrs.autocorrect).toBe('off');
+ expect(textarea.attrs.spellcheck).toBe('false');
+ expect(CjkInput.holdUntilEnter).toBe(false);
+ });
+
+ it('grows the field with its text and re-runs the keyboard layout', () => {
+ const { textarea, layout } = load();
+ layout.mockClear();
+ textarea.scrollHeight = 60;
+ type(textarea, 'a\nb\nc');
+ vi.advanceTimersByTime(1000);
+ expect(textarea.style.height).toBe('60px');
+ expect(layout).toHaveBeenCalled();
+ });
+
+ it('live mode is unchanged: text streams after the debounce', () => {
+ const { textarea, sent } = load({ hold: false });
+ type(textarea, 'hi');
+ vi.advanceTimersByTime(1000);
+ expect(sent).toEqual(['hi']);
+ });
+});