fix(mobile): the clear-line key discards a Send on Enter draft

clear({ discard: true }) skips the owner stash, drops any older stash of
the owner and keeps the owner; clearTerminalInput() (the keyboard bar's
clear-line key) uses it, so a cleared draft does not come back on a
same-tab reload or a switch back. @fileoverview gains a Send on Enter
section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kamil KaliszandClaude Opus 5.5 committed 2026-11-17 00:37:16 +01:00
1 parent 673a656538
commit 387cb830f4
3 files changed
+64 -10

No files matched your search

+31 -9
View File
@@ -7,6 +7,21 @@
* While this textarea has focus, window.cjkActive = true blocks xterm's onData.
* Arrow keys and function keys are forwarded to PTY directly.
*
* ## Send on Enter (setting cjkInputHoldUntilEnter)
*
* The live mode above streams typed text to the PTY after a short debounce.
* With Send on Enter on, the field is a chat box instead: _flush() holds the
* text, and only Enter sends it, through the sendPrompt callback
* (terminal-ui.js _sendCjkPrompt: a single character is typed, anything longer
* goes as the composer's bracketed paste, Enter is always its own later write,
* and a lone digit at a pending dialog goes without it). Shift+Enter is a
* newline, Esc clears, Backspace and the arrows reach the PTY only from an
* empty field, and so do the Ctrl shortcuts. Autocorrect is on. A held draft
* belongs to one session (_owner): clear() stashes it under that session and
* restoreDraft() brings it back when the session is shown again, except a
* clear({ discard: true }) (the keyboard bar's clear-line key), which throws
* it away.
*
* ## Android IME challenge
*
* Android virtual keyboards (WeChat, Sogou, Gboard in Chinese mode) use
@@ -621,17 +636,24 @@ const CjkInput = (() => {
* can't flush into the wrong session). Restores the phantom so backspace
* forwarding keeps working — unlike a raw `textarea.value = ''`.
*/
clear() {
clear({ discard = false } = {}) {
if (!_initialized || !_textarea) return;
_t('clear (external)');
// Send-on-Enter: a held draft is stashed for the session it was typed
// for, whichever path got here. discardDraft() drops the owner of a
// removed session, so its text is not stashed again.
if (_hold && _owner) {
const draft = _strip(_textarea.value);
if (draft.trim()) _drafts.set(_owner, draft);
_t(`clear (external)${discard ? ' discard' : ''}`);
if (discard) {
// The user threw the text away (the keyboard bar's clear-line key):
// nothing is stashed, any older stash of this session goes too, and the
// field keeps its owner, since the session shown has not changed.
if (_owner) _drafts.delete(_owner);
} else {
// Send-on-Enter: a held draft is stashed for the session it was typed
// for, whichever path got here. discardDraft() drops the owner of a
// removed session, so its text is not stashed again.
if (_hold && _owner) {
const draft = _strip(_textarea.value);
if (draft.trim()) _drafts.set(_owner, draft);
}
_owner = null;
}
_owner = null;
_cancelDebouncedFlush();
clearTimeout(_compositionFlushTimer);
_compositionFlushTimer = null;
+3 -1
View File
@@ -5134,7 +5134,9 @@ Object.assign(CodemanApp.prototype, {
clearTerminalInput() {
if (!this.activeSessionId) return;
if (typeof CjkInput !== 'undefined') CjkInput.clear();
// discard: the line is thrown away, so a Send on Enter draft must not be
// stashed and come back on the next visit to this session.
if (typeof CjkInput !== 'undefined') CjkInput.clear({ discard: true });
// A tile or Pane B holds the keyboard: its TUI owns the editable buffer
// (no local-echo overlay there), so kill the line in that pane's session,
// never in the parked main pane's.
+30
View File
@@ -428,6 +428,36 @@ describe('CJK input: Send on Enter', () => {
expect(sent).toEqual([]);
});
it('clear({ discard }) throws the draft away: a same-tab restore and a switch back stay empty', () => {
// The keyboard bar's clear-line key (terminal-ui.js clearTerminalInput).
const { CjkInput, textarea } = load();
CjkInput.restoreDraft('session-a');
type(textarea, 'thrown away');
CjkInput.clear({ discard: true });
expect(textarea.value).toBe(PHANTOM);
expect(CjkInput.draftOwner).toBe('session-a');
// Tapping the session's own tab: the field is kept, then restoreDraft runs.
CjkInput.restoreDraft('session-a');
expect(textarea.value).toBe(PHANTOM);
// Switching away and back.
CjkInput.clear();
CjkInput.restoreDraft('session-b');
CjkInput.clear();
CjkInput.restoreDraft('session-a');
expect(textarea.value).toBe(PHANTOM);
});
it('clear({ discard }) also drops an older stash of the same session', () => {
const { CjkInput, textarea } = load();
CjkInput.restoreDraft('session-a');
type(textarea, 'old');
CjkInput.stashDraft('session-a');
CjkInput.clear({ discard: true });
CjkInput.clear();
CjkInput.restoreDraft('session-a');
expect(textarea.value).toBe(PHANTOM);
});
it('a removed session loses its field text: discardDraft drops the owner', () => {
const { CjkInput, textarea } = load();
CjkInput.restoreDraft('session-a');