mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(mobile): turning Send on Enter off drops the held draft
setHoldUntilEnter going from on to off clears the stashed drafts and resets the field, so live mode's next flush sends only the new key, not a held multi-line draft. The invariants doc and the _handleCjkInput comment name _sendCjkPrompt as the path a held answer takes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
387cb830f4
commit
57fdb52f7c
4 files changed
+30
-3
No files matched your search
@@ -1269,7 +1269,7 @@ The age stamps are refreshed **in place** by a 20s clock (`_tickHomeSessionsTime
|
||||
|
||||
⚠️ It must disarm on ALL of: use, second tap, any other accessory key, session switch, keyboard dismissal, and a layout swap; a modifier left armed turns the next innocent keystroke into a control byte.
|
||||
|
||||
⚠️ **onData is not the only input path** — with `cjkInputEnabled` on, the CJK textarea owns the keyboard (onData returns early for everything it swallows, and the focus router sends `terminal.focus()` there, which is where the bar refocuses after every key), so `_handleCjkInput()` applies the modifier too. It is that module's single choke point to the PTY, so one call covers typed characters, IME flushes, Enter, backspace and arrows. Without it an armed modifier could neither fire NOR be spent, and survived to a later keystroke.
|
||||
⚠️ **onData is not the only input path** — with `cjkInputEnabled` on, the CJK textarea owns the keyboard (onData returns early for everything it swallows, and the focus router sends `terminal.focus()` there, which is where the bar refocuses after every key), so `_handleCjkInput()` applies the modifier too. It is that module's single choke point to the PTY in live mode, so one call covers typed characters, IME flushes, Enter, backspace and arrows; in Send on Enter a held answer leaves through `_sendCjkPrompt()` instead, which spends the modifier, while an armed next character still goes through `_handleCjkInput()`. Without it an armed modifier could neither fire NOR be spent, and survived to a later keystroke.
|
||||
|
||||
Mapping is `ctrlByteFor()` (`code & 0x1f` over @A-Z[\]^_ and a-z, plus Ctrl+Space=NUL / Ctrl+?=DEL); characters with no control equivalent pass through unchanged, like a hardware keyboard.
|
||||
|
||||
|
||||
@@ -672,9 +672,18 @@ const CjkInput = (() => {
|
||||
// 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;
|
||||
const wasHolding = _hold;
|
||||
_hold = !!on;
|
||||
if (!_textarea) return;
|
||||
_holdApplied = true;
|
||||
// Turning the mode off: live mode's next flush would send everything in
|
||||
// the field, a held multi-line draft included (its newline runs the first
|
||||
// line in a shell), and stashed drafts would come back if the mode is
|
||||
// switched on again. Drop them all.
|
||||
if (wasHolding && !_hold) {
|
||||
_drafts.clear();
|
||||
_resetToPhantom();
|
||||
}
|
||||
_heldBase = _strip(_textarea.value);
|
||||
const v = _hold ? 'on' : 'off';
|
||||
_textarea.setAttribute('autocorrect', v);
|
||||
|
||||
@@ -4555,8 +4555,10 @@ Object.assign(CodemanApp.prototype, {
|
||||
// after every key. So the onData hook never sees these keystrokes, and an
|
||||
// armed modifier could neither fire NOR be spent: it survived until a
|
||||
// session switch and then turned an innocent keystroke into a control byte.
|
||||
// This is the module's single choke point to the PTY, so applying it here
|
||||
// covers typed characters, IME flushes, Enter, backspace and arrows at once.
|
||||
// This is the module's single choke point to the PTY in live mode, so applying
|
||||
// it here covers typed characters, IME flushes, Enter, backspace and arrows at
|
||||
// once. In Send on Enter a held answer leaves through _sendCjkPrompt instead,
|
||||
// which spends the modifier; an armed next character still comes here.
|
||||
// Same policy as the onData hook: the next single character is modified,
|
||||
// anything longer merely spends the modifier.
|
||||
if (typeof KeyboardAccessoryBar !== 'undefined' && KeyboardAccessoryBar.isCtrlArmed?.()) {
|
||||
|
||||
@@ -305,6 +305,22 @@ describe('CJK input: Send on Enter', () => {
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('turning the mode off drops the held draft and the stashes, so live mode sends only new keys', () => {
|
||||
const { CjkInput, textarea, sent } = load();
|
||||
CjkInput.restoreDraft('session-a');
|
||||
type(textarea, 'rm -rf build\nsecond line');
|
||||
CjkInput.stashDraft('session-b');
|
||||
CjkInput.setHoldUntilEnter(false);
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
type(textarea, 'x');
|
||||
vi.advanceTimersByTime(1000);
|
||||
expect(sent).toEqual(['x']);
|
||||
CjkInput.setHoldUntilEnter(true);
|
||||
CjkInput.clear();
|
||||
CjkInput.restoreDraft('session-b');
|
||||
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');
|
||||
|
||||
Reference in new issue
Block a user