mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
fix(web): bind Send on Enter to the captured session, keep the voice draft (#830)
Held-mode Ctrl, Backspace and restored drafts send to the session their text was typed for; a Ctrl-only field releases it. Voice compose Send settles the iOS owner without flushing the unsent local-echo draft. Cover Send on Enter across focus moves, the toolbar Enter in the CJK field and the same-session reload. Describe Pane B iOS input ownership; drop a stub for a removed helper.
This commit is contained in:
1 parent
eb22f10fd4
commit
ddb5a647ba
8 files changed
+254
-85
No files matched your search
@@ -554,27 +554,43 @@ describe('one-shot Ctrl through the CJK input field', () => {
|
||||
});
|
||||
|
||||
describe('Send on Enter: a held answer goes out with Enter as its own write', () => {
|
||||
// _sendCjkPrompt is CjkInput's sendPrompt callback. Anything longer than one
|
||||
// character goes to the composer's _sendComposedPrompt with the session
|
||||
// captured at Enter, so the delayed Enter cannot follow a tab switch.
|
||||
// _sendCjkPrompt is CjkInput's sendPrompt callback, called with the session
|
||||
// CjkInput captured for the text (_targetForSend). Anything longer than one
|
||||
// character goes to the composer's _sendComposedPrompt for that session; one
|
||||
// character, the 120 ms gap and Enter are reserved on that session's FIFO, so
|
||||
// the delayed Enter cannot follow a tab switch.
|
||||
type PromptApp = {
|
||||
activeSessionId: string | null;
|
||||
sessions: Map<string, { mode: string }>;
|
||||
pendingHooks?: Map<string, Set<string>>;
|
||||
_focusedPane(): { sessionId: string | null; terminal: object; isPrimary: boolean } | null;
|
||||
_paneForSession(id: string): null;
|
||||
_enqueueReliableInput(id: string, input: string, opts?: { useMux?: boolean }): void;
|
||||
_sendCjkPrompt(text: string, sessionId?: string): boolean;
|
||||
};
|
||||
function promptApp() {
|
||||
const { CodemanApp, bar } = loadTerminalModule();
|
||||
bar.clearCtrl();
|
||||
const app = Object.create(CodemanApp.prototype) as {
|
||||
activeSessionId: string | null;
|
||||
_sendCjkPrompt(text: string): boolean;
|
||||
};
|
||||
const app = Object.create(CodemanApp.prototype) as PromptApp;
|
||||
app.activeSessionId = 'session-a';
|
||||
app.sessions = new Map([
|
||||
['session-a', { mode: 'claude' }],
|
||||
['session-b', { mode: 'claude' }],
|
||||
]);
|
||||
app._focusedPane = () => ({ sessionId: app.activeSessionId, terminal: {}, isPrimary: true });
|
||||
app._paneForSession = () => null;
|
||||
const writes: Array<[string, string, boolean]> = [];
|
||||
app._enqueueReliableInput = (id, input, opts) => void writes.push([id, input, opts?.useMux === true]);
|
||||
const composed = vi
|
||||
.spyOn(bar as unknown as { _sendComposedPrompt: (s: string, t: string) => boolean }, '_sendComposedPrompt')
|
||||
.mockReturnValue(true);
|
||||
return { app, bar, composed };
|
||||
return { app, bar, composed, writes };
|
||||
}
|
||||
|
||||
it('sends through the composer path, bound to the session active at Enter', () => {
|
||||
it('sends through the composer path for the captured session, not the active one', () => {
|
||||
const { app, composed } = promptApp();
|
||||
expect(app._sendCjkPrompt('line one\nline two')).toBe(true);
|
||||
app.activeSessionId = 'session-b';
|
||||
expect(app._sendCjkPrompt('line one\nline two', 'session-a')).toBe(true);
|
||||
expect(composed).toHaveBeenCalledWith('session-a', 'line one\nline two');
|
||||
composed.mockRestore();
|
||||
});
|
||||
@@ -582,28 +598,28 @@ describe('Send on Enter: a held answer goes out with Enter as its own write', ()
|
||||
it('spends an armed one-shot Ctrl, like any multi-character chunk', () => {
|
||||
const { app, bar, composed } = promptApp();
|
||||
bar.toggleCtrl();
|
||||
app._sendCjkPrompt('x'.repeat(100));
|
||||
app._sendCjkPrompt('x'.repeat(100), 'session-a');
|
||||
expect(bar.isCtrlArmed()).toBe(false);
|
||||
composed.mockRestore();
|
||||
});
|
||||
|
||||
it('types a single character, then Enter ~120 ms later to the same session', () => {
|
||||
it('types a single character, then Enter 120 ms later on the same session FIFO across a switch', () => {
|
||||
// Codex folds an Enter that arrives in the same burst as the text into a
|
||||
// paste, even for `1\r`; a selection dialog ignores a pasted digit. Same
|
||||
// split as TmuxManager.sendInput (submitsAsKeys).
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const { app, composed } = promptApp();
|
||||
const writes: Array<[string, string, unknown]> = [];
|
||||
(app as unknown as { _sendInputAsync: unknown })._sendInputAsync = (id: string, input: string, opts?: unknown) =>
|
||||
writes.push([id, input, opts]);
|
||||
expect(app._sendCjkPrompt('1')).toBe(true);
|
||||
expect(writes).toEqual([['session-a', '1', undefined]]);
|
||||
const { app, composed, writes } = promptApp();
|
||||
expect(app._sendCjkPrompt('1', 'session-a')).toBe(true);
|
||||
expect(writes).toEqual([['session-a', '1', false]]);
|
||||
app.activeSessionId = 'session-b';
|
||||
vi.advanceTimersByTime(119);
|
||||
expect(writes).toHaveLength(1);
|
||||
vi.advanceTimersByTime(1);
|
||||
expect(writes[1]).toEqual(['session-a', '\r', { useMux: true }]);
|
||||
expect(writes).toEqual([
|
||||
['session-a', '1', false],
|
||||
['session-a', '\r', true],
|
||||
]);
|
||||
expect(composed).not.toHaveBeenCalled();
|
||||
composed.mockRestore();
|
||||
} finally {
|
||||
@@ -618,19 +634,11 @@ describe('Send on Enter: a held answer goes out with Enter as its own write', ()
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
for (const hook of ['permission_prompt', 'elicitation_dialog']) {
|
||||
const { app, composed } = promptApp();
|
||||
const writes: Array<[string, string, unknown]> = [];
|
||||
(app as unknown as { _sendInputAsync: unknown })._sendInputAsync = (
|
||||
id: string,
|
||||
input: string,
|
||||
opts?: unknown
|
||||
) => writes.push([id, input, opts]);
|
||||
(app as unknown as { pendingHooks: Map<string, Set<string>> }).pendingHooks = new Map([
|
||||
['session-a', new Set([hook])],
|
||||
]);
|
||||
expect(app._sendCjkPrompt('2')).toBe(true);
|
||||
const { app, composed, writes } = promptApp();
|
||||
app.pendingHooks = new Map([['session-a', new Set([hook])]]);
|
||||
expect(app._sendCjkPrompt('2', 'session-a')).toBe(true);
|
||||
vi.advanceTimersByTime(500);
|
||||
expect(writes).toEqual([['session-a', '2', undefined]]);
|
||||
expect(writes).toEqual([['session-a', '2', false]]);
|
||||
composed.mockRestore();
|
||||
}
|
||||
} finally {
|
||||
@@ -646,21 +654,13 @@ describe('Send on Enter: a held answer goes out with Enter as its own write', ()
|
||||
['permission_prompt', 'y'],
|
||||
];
|
||||
for (const [hook, text] of cases) {
|
||||
const { app, composed } = promptApp();
|
||||
const writes: Array<[string, string, unknown]> = [];
|
||||
(app as unknown as { _sendInputAsync: unknown })._sendInputAsync = (
|
||||
id: string,
|
||||
input: string,
|
||||
opts?: unknown
|
||||
) => writes.push([id, input, opts]);
|
||||
(app as unknown as { pendingHooks: Map<string, Set<string>> }).pendingHooks = new Map([
|
||||
['session-a', new Set([hook])],
|
||||
]);
|
||||
expect(app._sendCjkPrompt(text)).toBe(true);
|
||||
const { app, composed, writes } = promptApp();
|
||||
app.pendingHooks = new Map([['session-a', new Set([hook])]]);
|
||||
expect(app._sendCjkPrompt(text, 'session-a')).toBe(true);
|
||||
vi.advanceTimersByTime(120);
|
||||
expect(writes).toEqual([
|
||||
['session-a', text, undefined],
|
||||
['session-a', '\r', { useMux: true }],
|
||||
['session-a', text, false],
|
||||
['session-a', '\r', true],
|
||||
]);
|
||||
composed.mockRestore();
|
||||
}
|
||||
@@ -671,19 +671,22 @@ describe('Send on Enter: a held answer goes out with Enter as its own write', ()
|
||||
|
||||
it('pastes even a short word: only one character is typed', () => {
|
||||
const { app, composed } = promptApp();
|
||||
expect(app._sendCjkPrompt('yes')).toBe(true);
|
||||
expect(app._sendCjkPrompt('yes', 'session-a')).toBe(true);
|
||||
expect(composed).toHaveBeenCalledWith('session-a', 'yes');
|
||||
composed.mockRestore();
|
||||
});
|
||||
|
||||
it('reports a refusal so the field keeps the text', () => {
|
||||
const { app, composed } = promptApp();
|
||||
const { app, composed, writes } = promptApp();
|
||||
composed.mockReturnValue(false);
|
||||
expect(app._sendCjkPrompt('x'.repeat(100))).toBe(false);
|
||||
expect(app._sendCjkPrompt('x'.repeat(100), 'session-a')).toBe(false);
|
||||
// A captured session that closed meanwhile, or no session at all, sends nothing.
|
||||
expect(app._sendCjkPrompt('1', 'session-gone')).toBe(false);
|
||||
app.activeSessionId = null;
|
||||
expect(app._sendCjkPrompt('x'.repeat(100))).toBe(false);
|
||||
expect(app._sendCjkPrompt('1')).toBe(false);
|
||||
expect(composed).toHaveBeenCalledTimes(1);
|
||||
expect(writes).toEqual([]);
|
||||
composed.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user