mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
fix(mobile): Send on Enter placeholder i18n, one-line field on desktop
- input-cjk.js translates its placeholder with CodemanI18n.t(), like the prompt composer, since i18n.js skips <textarea> subtrees; the zh-CN entries now show. - The field only grows on touch devices, where it is position: fixed. On a desktop it sits under the terminal, so growing would shrink the terminal box and resize the PTY on every line; it stays one line and scrolls there. - Input And Voice: a line break needs a hardware keyboard (no Shift+Enter on a phone keyboard, and the extended bar's newline key goes to the CLI). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57fdb52f7c
commit
3c5b7e2199
3 files changed
+56
-15
No files matched your search
@@ -69,17 +69,19 @@ sequences, so word jumps and history keys keep working.
|
||||
|
||||
On a phone, **Input Field: Send on Enter** (beside CJK input) turns that field into a chat box:
|
||||
typed text stays in it until Enter, so you can scroll the terminal back to a question and edit
|
||||
your answer before sending. Shift+Enter adds a line, Esc clears the field, and autocorrect is on.
|
||||
Enter always goes out as its own write, a moment after the text, to the session the answer was
|
||||
typed for: a single character is typed, so CLI menus that take a digit still work, and anything
|
||||
longer goes like the prompt composer's Send, as one paste. The one exception is a lone digit while
|
||||
a permission or question dialog is waiting: the digit answers the dialog by itself, so no Enter
|
||||
follows it, which would otherwise confirm whatever the CLI shows next. The toolbar's Enter button
|
||||
sends the field too. With the keyboard bar's one-shot Ctrl armed, the next key you type goes out
|
||||
as a control key (Ctrl, then `c` is Ctrl+C) instead of being held. With a hardware keyboard, Ctrl
|
||||
shortcuts (undo, select all, copy) act on the field while it holds a draft and reach the CLI only
|
||||
when it is empty. With the keyboard down the field stays one line tall. A draft stays with its
|
||||
session: switching tabs and coming back brings it back.
|
||||
your answer before sending. With a hardware keyboard, Shift+Enter adds a line (a phone's on-screen
|
||||
keyboard has no Shift+Enter, and the extended bar's newline key goes to the CLI, not the field),
|
||||
Esc clears the field, and autocorrect is on. Enter always goes out as its own write, a moment
|
||||
after the text, to the session the answer was typed for: a single character is typed, so CLI menus
|
||||
that take a digit still work, and anything longer goes like the prompt composer's Send, as one
|
||||
paste. The one exception is a lone digit while a permission or question dialog is waiting: the
|
||||
digit answers the dialog by itself, so no Enter follows it, which would otherwise confirm whatever
|
||||
the CLI shows next. The toolbar's Enter button sends the field too. With the keyboard bar's
|
||||
one-shot Ctrl armed, the next key you type goes out as a control key (Ctrl, then `c` is Ctrl+C)
|
||||
instead of being held. With a hardware keyboard, Ctrl shortcuts (undo, select all, copy) act on
|
||||
the field while it holds a draft and reach the CLI only when it is empty. With the keyboard down
|
||||
the field stays one line tall. A draft stays with its session: switching tabs and coming back
|
||||
brings it back.
|
||||
|
||||
## Voice dictation
|
||||
|
||||
|
||||
@@ -251,6 +251,15 @@ const CjkInput = (() => {
|
||||
_textarea.style.height = '';
|
||||
return;
|
||||
}
|
||||
// Only a touch device grows the field: there it is position: fixed above the
|
||||
// keyboard. On a desktop it sits in the flex column under the terminal, so
|
||||
// every line it gained would shrink the terminal box, refit and resize the
|
||||
// session's PTY (a CLI repaint each time). It stays one line there and
|
||||
// scrolls inside instead.
|
||||
if (!document.body?.classList?.contains('touch-device')) {
|
||||
_textarea.style.height = '';
|
||||
return;
|
||||
}
|
||||
const before = _textarea.style.height;
|
||||
_textarea.style.height = 'auto';
|
||||
// border-box: scrollHeight leaves the borders out, offsetHeight - clientHeight adds them back.
|
||||
@@ -689,9 +698,13 @@ const CjkInput = (() => {
|
||||
_textarea.setAttribute('autocorrect', v);
|
||||
_textarea.setAttribute('autocapitalize', _hold ? 'sentences' : 'off');
|
||||
_textarea.setAttribute('spellcheck', _hold ? 'true' : 'false');
|
||||
_textarea.placeholder = _hold
|
||||
// i18n.js skips <textarea> subtrees (what is typed there is user content),
|
||||
// so the placeholder is translated here, like the prompt composer's.
|
||||
const placeholder = _hold
|
||||
? 'Type, Enter to send (Shift+Enter: new line, Esc: clear)'
|
||||
: 'CJK input (Enter = send, Esc = clear)';
|
||||
const i18n = typeof window !== 'undefined' ? window.CodemanI18n : undefined;
|
||||
_textarea.placeholder = typeof i18n?.t === 'function' ? i18n.t(placeholder) : placeholder;
|
||||
if (_hold) {
|
||||
_cancelDebouncedFlush();
|
||||
_autoGrow();
|
||||
|
||||
@@ -49,7 +49,12 @@ function makeTextarea() {
|
||||
};
|
||||
}
|
||||
|
||||
function load({ hold = true, promptResult = true } = {}) {
|
||||
function load({
|
||||
hold = true,
|
||||
promptResult = true,
|
||||
touch = true,
|
||||
translate,
|
||||
}: { hold?: boolean; promptResult?: boolean; touch?: boolean; translate?: (s: string) => string } = {}) {
|
||||
const textarea = makeTextarea();
|
||||
const sent: string[] = [];
|
||||
const prompts: string[] = [];
|
||||
@@ -65,8 +70,12 @@ function load({ hold = true, promptResult = true } = {}) {
|
||||
},
|
||||
};
|
||||
const context = vm.createContext({
|
||||
window: {},
|
||||
document: { getElementById: (id: string) => (id === 'cjkInput' ? textarea : null), activeElement: null },
|
||||
window: translate ? { CodemanI18n: { t: translate } } : {},
|
||||
document: {
|
||||
getElementById: (id: string) => (id === 'cjkInput' ? textarea : null),
|
||||
activeElement: null,
|
||||
body: { classList: { contains: (c: string) => touch && c === 'touch-device' } },
|
||||
},
|
||||
navigator: { userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X)' },
|
||||
KeyboardHandler: { updateLayoutForKeyboard: layout },
|
||||
KeyboardAccessoryBar: bar,
|
||||
@@ -321,6 +330,23 @@ describe('CJK input: Send on Enter', () => {
|
||||
expect(textarea.value).toBe(PHANTOM);
|
||||
});
|
||||
|
||||
it('stays one line on a desktop, where growing would resize the PTY', () => {
|
||||
const { textarea, layout } = load({ touch: false });
|
||||
layout.mockClear();
|
||||
textarea.scrollHeight = 60;
|
||||
type(textarea, 'a\nb\nc');
|
||||
vi.advanceTimersByTime(1000);
|
||||
expect(textarea.style.height).toBe('');
|
||||
expect(layout).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('translates its placeholder itself, since i18n.js skips textareas', () => {
|
||||
const { CjkInput, textarea } = load({ translate: (s) => `zh:${s}` });
|
||||
expect(textarea.placeholder).toBe('zh:Type, Enter to send (Shift+Enter: new line, Esc: clear)');
|
||||
CjkInput.setHoldUntilEnter(false);
|
||||
expect(textarea.placeholder).toBe('zh:CJK input (Enter = send, Esc = clear)');
|
||||
});
|
||||
|
||||
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