mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-02 08:59:32 +01:00
fix(mobile): Send on Enter review fixes
- A long single line (over 64 characters) or several lines now go through the composer's _sendComposedPrompt: one bracketed paste, then Enter as a separate delayed write to the session captured at Enter. Claude Code took a long `<text>\r` burst as a paste and left it unsent, and the old delayed Enter followed a tab switch. A refused prompt keeps the text in the field. - Deleting held text no longer sends Backspace to the PTY. It goes out only when the field was already empty (the phantom itself deleted), so select-all + delete is covered too. - With the one-shot Ctrl armed, the next single typed character skips the hold and reaches _handleCjkInput, which turns it into the control byte; any other change spends the modifier, as in live mode. - A reload of the session already shown (tapping its tab, the geometry retry) keeps a held draft. - With the keyboard down the field stays one line tall, so it no longer covers the terminal's last rows. - zh-CN strings for both field placeholders, and a test pinning cjkInputHoldUntilEnter as per-device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b8a4466643
commit
95fb147e9c
9 files changed
+474
-33
No files matched your search
+148
-15
@@ -45,15 +45,27 @@ function makeTextarea() {
|
||||
};
|
||||
}
|
||||
|
||||
function load({ hold = true } = {}) {
|
||||
function load({ hold = true, promptResult = true } = {}) {
|
||||
const textarea = makeTextarea();
|
||||
const sent: string[] = [];
|
||||
const prompts: string[] = [];
|
||||
const layout = vi.fn();
|
||||
// The shell bar's one-shot Ctrl, reduced to its armed flag.
|
||||
const bar = {
|
||||
armed: false,
|
||||
isCtrlArmed() {
|
||||
return this.armed;
|
||||
},
|
||||
clearCtrl() {
|
||||
this.armed = false;
|
||||
},
|
||||
};
|
||||
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 },
|
||||
KeyboardAccessoryBar: bar,
|
||||
setTimeout: (fn: () => void, ms?: number) => setTimeout(fn, ms),
|
||||
clearTimeout: (t: ReturnType<typeof setTimeout>) => clearTimeout(t),
|
||||
performance: { now: () => performance.now() },
|
||||
@@ -62,10 +74,16 @@ function load({ hold = true } = {}) {
|
||||
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.init({
|
||||
send: (t: string) => sent.push(t),
|
||||
sendPrompt: (t: string) => {
|
||||
prompts.push(t);
|
||||
return promptResult;
|
||||
},
|
||||
});
|
||||
CjkInput.setHoldUntilEnter(hold);
|
||||
textarea.fire('focus');
|
||||
return { CjkInput, textarea, sent, layout };
|
||||
return { CjkInput, textarea, sent, prompts, layout, bar };
|
||||
}
|
||||
|
||||
function type(textarea: ReturnType<typeof makeTextarea>, text: string) {
|
||||
@@ -73,6 +91,14 @@ function type(textarea: ReturnType<typeof makeTextarea>, text: string) {
|
||||
textarea.fire('input', { isComposing: false, inputType: 'insertText' });
|
||||
}
|
||||
|
||||
function backspace(textarea: ReturnType<typeof makeTextarea>, valueAfter: string) {
|
||||
textarea.value = valueAfter;
|
||||
textarea.fire('input', { isComposing: false, inputType: 'deleteContentBackward' });
|
||||
}
|
||||
|
||||
const enter = (textarea: ReturnType<typeof makeTextarea>) =>
|
||||
textarea.fire('keydown', { key: 'Enter', keyCode: 13, shiftKey: false });
|
||||
|
||||
describe('CJK input: Send on Enter', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date', 'performance'] });
|
||||
@@ -127,20 +153,43 @@ describe('CJK input: Send on Enter', () => {
|
||||
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('sends a long single line as a prompt, never as one <text>\\r burst', () => {
|
||||
// Claude Code takes a burst of ~100+ characters as a paste and its \r as a
|
||||
// newline, so the answer would sit unsent (src/web/route-helpers.ts).
|
||||
const { textarea, sent, prompts } = load();
|
||||
const long = 'x'.repeat(150);
|
||||
type(textarea, long);
|
||||
enter(textarea);
|
||||
expect(sent).toEqual([]);
|
||||
expect(prompts).toEqual([long]);
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
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('keeps a line at the direct-write limit as one write, one over it as a prompt', () => {
|
||||
const { textarea, sent, prompts } = load();
|
||||
type(textarea, 'a'.repeat(64));
|
||||
enter(textarea);
|
||||
type(textarea, 'b'.repeat(65));
|
||||
enter(textarea);
|
||||
expect(sent).toEqual(['a'.repeat(64) + '\r']);
|
||||
expect(prompts).toEqual(['b'.repeat(65)]);
|
||||
});
|
||||
|
||||
it('sends several lines as a prompt (bracketed paste + session-bound Enter)', () => {
|
||||
const { textarea, sent, prompts } = load();
|
||||
type(textarea, 'line one\nline two');
|
||||
enter(textarea);
|
||||
vi.advanceTimersByTime(500);
|
||||
expect(prompts).toEqual(['line one\nline two']);
|
||||
expect(sent).toEqual([]);
|
||||
});
|
||||
|
||||
it('keeps the text in the field when the prompt is refused (too long, no session)', () => {
|
||||
const { textarea, prompts } = load({ promptResult: false });
|
||||
type(textarea, 'line one\nline two');
|
||||
enter(textarea);
|
||||
expect(prompts).toHaveLength(1);
|
||||
expect(textarea.value).toBe(PHANTOM + 'line one\nline two');
|
||||
});
|
||||
|
||||
it('treats Shift+Enter as a newline, never a send', () => {
|
||||
@@ -165,6 +214,90 @@ describe('CJK input: Send on Enter', () => {
|
||||
expect(sent).toEqual(['\x7f']);
|
||||
});
|
||||
|
||||
it('does not send Backspace when deleting the last held character', () => {
|
||||
// The CLI's own composer may hold text (Attach, image paste, Path, mic):
|
||||
// a stray DEL would eat its last character.
|
||||
const { textarea, sent } = load();
|
||||
type(textarea, 'a');
|
||||
type(textarea, 'ab');
|
||||
backspace(textarea, PHANTOM + 'a');
|
||||
backspace(textarea, PHANTOM);
|
||||
expect(sent).toEqual([]);
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('sends Backspace once the field is empty and the phantom itself is deleted', () => {
|
||||
const { textarea, sent } = load();
|
||||
type(textarea, 'a');
|
||||
backspace(textarea, PHANTOM);
|
||||
backspace(textarea, '');
|
||||
expect(sent).toEqual(['\x7f']);
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('does not send Backspace for select-all + delete of held text', () => {
|
||||
const { textarea, sent } = load();
|
||||
type(textarea, 'abc');
|
||||
backspace(textarea, '');
|
||||
expect(sent).toEqual([]);
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('deletes held text right after typing it, before any debounce, without a DEL', () => {
|
||||
const { textarea, sent } = load();
|
||||
type(textarea, 'a');
|
||||
backspace(textarea, PHANTOM);
|
||||
vi.advanceTimersByTime(2000);
|
||||
expect(sent).toEqual([]);
|
||||
});
|
||||
|
||||
it('puts the phantom back when Backspace at the start of the text deleted it', () => {
|
||||
const { textarea, sent } = load();
|
||||
type(textarea, 'abc');
|
||||
backspace(textarea, 'abc');
|
||||
expect(sent).toEqual([]);
|
||||
expect(textarea.value).toBe(PHANTOM + 'abc');
|
||||
});
|
||||
|
||||
it('one-shot Ctrl: the next typed character goes out instead of being held', () => {
|
||||
// _handleCjkInput turns the single character into the control byte.
|
||||
const { textarea, sent, bar } = load();
|
||||
bar.armed = true;
|
||||
type(textarea, 'c');
|
||||
expect(sent).toEqual(['c']);
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('one-shot Ctrl: held text stays and only the new character leaves the field', () => {
|
||||
const { textarea, sent, bar } = load();
|
||||
type(textarea, 'ab');
|
||||
bar.armed = true;
|
||||
type(textarea, 'abc');
|
||||
expect(sent).toEqual(['c']);
|
||||
expect(textarea.value).toBe(PHANTOM + 'ab');
|
||||
});
|
||||
|
||||
it('one-shot Ctrl: a character committed by an IME composition also goes out', () => {
|
||||
const { textarea, sent, bar } = load();
|
||||
bar.armed = true;
|
||||
textarea.fire('compositionstart');
|
||||
textarea.value = PHANTOM + 'c';
|
||||
textarea.fire('input', { isComposing: true, inputType: 'insertCompositionText' });
|
||||
textarea.fire('compositionend');
|
||||
vi.advanceTimersByTime(10);
|
||||
expect(sent).toEqual(['c']);
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('one-shot Ctrl: a multi-character commit stays held and spends the modifier', () => {
|
||||
const { textarea, sent, bar } = load();
|
||||
bar.armed = true;
|
||||
type(textarea, 'hello');
|
||||
expect(sent).toEqual([]);
|
||||
expect(textarea.value).toBe(PHANTOM + 'hello');
|
||||
expect(bar.armed).toBe(false);
|
||||
});
|
||||
|
||||
it('Escape clears the held text without sending', () => {
|
||||
const { textarea, sent } = load();
|
||||
type(textarea, 'never mind');
|
||||
|
||||
Reference in new issue
Block a user