From decbd58bb480a652fa745d858efa0dfe509dee3f Mon Sep 17 00:00:00 2001 From: Ananovo Date: Fri, 13 Nov 2026 18:48:42 +0800 Subject: [PATCH] feat(web): add Alt+S shortcut to send messages (#1658) * feat(web): add Alt+S send shortcut * chore: retrigger PR checks * fix(web): preserve printable Option characters for Alt+S * fix(web): support logical Alt+S across layouts * test(web): cover Alt+S during IME composition --- web/README.md | 1 + .../HappyComposer.sendError.test.tsx | 52 ++++++++++++++++++- .../AssistantChat/HappyComposer.tsx | 17 ++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/web/README.md b/web/README.md index fea7bdb6..e6e31161 100644 --- a/web/README.md +++ b/web/README.md @@ -80,6 +80,7 @@ The Hub persists and enforces the lock across clients, restarts, and resume. - Message thread with infinite scroll. - Concise view (header toggle or `/settings/chat`, per device): shows only user input and each round's final reply (`src/chat/conciseView.ts`). Permission requests, questions, plan proposals, user shell commands, and errors stay visible; the full thread returns while a search target is active. - Composer for sending messages. +- Composer send shortcut: Alt+S (independent of the Enter behavior setting). - A collapsible **Awaiting your reply** section above the composer collects all live non-blocking `request_user_input` questions, including those outside the loaded transcript. Answer there or dismiss individual questions without sending an answer or stopping the agent. Collapsing preserves drafts; blocking permissions retain their existing controls. - Permission mode and model selection for supported agents. Cursor Auto uses CLI Auto for new/resumed sessions configured with Auto. Switching a live session to Auto when ACP does not advertise a literal Auto option relaunches the Cursor ACP process in place under `--model auto` while preserving the hub session id. diff --git a/web/src/components/AssistantChat/HappyComposer.sendError.test.tsx b/web/src/components/AssistantChat/HappyComposer.sendError.test.tsx index 5f456019..2e040dfb 100644 --- a/web/src/components/AssistantChat/HappyComposer.sendError.test.tsx +++ b/web/src/components/AssistantChat/HappyComposer.sendError.test.tsx @@ -33,6 +33,7 @@ const runtime = vi.hoisted(() => ({ pendingSendIntentRef: null as null | { current: ComposerSendIntent }, sentIntents: [] as ComposerSendIntent[], modelChanges: [] as Array<{ provider: string; modelId: string } | string | null>, + composerEnterBehavior: 'send' as 'send' | 'newline', pendingHydration: null as Promise | null, dictationEnabled: false, dictation: { status: 'connected', supported: true, partialTranscript: '', error: null, toggle: vi.fn(), stopAndSend: vi.fn() }, @@ -113,7 +114,9 @@ vi.mock('@/hooks/useDictation', () => ({ useDictation: () => runtime.dictation } vi.mock('@/hooks/useVoiceInputPreferences', () => ({ useVoiceInputPreferences: () => ({ voiceMode: runtime.dictationEnabled ? 'dictation' : 'conversation', provider: 'openai', transcriptionMode: 'standard' }), })) -vi.mock('@/hooks/useComposerEnterBehavior', () => ({ useComposerEnterBehavior: () => ({ composerEnterBehavior: 'send' }) })) +vi.mock('@/hooks/useComposerEnterBehavior', () => ({ + useComposerEnterBehavior: () => ({ composerEnterBehavior: runtime.composerEnterBehavior }), +})) vi.mock('@/hooks/usePlatform', () => ({ usePlatform: () => ({ haptic: { impact: () => {}, notification: () => {} }, isTouch: false }) })) vi.mock('@/hooks/usePWAInstall', () => ({ usePWAInstall: () => ({ isStandalone: false, isIOS: false }) })) vi.mock('@/hooks/useActiveWord', () => ({ useActiveWord: () => null })) @@ -249,10 +252,12 @@ function renderComposer( initialText = 'failed text', initialSchedule: PendingSchedule | null = { type: 'absolute', ms: 1234 }, piRunning = false, + composerEnterBehavior: 'send' | 'newline' = 'send', ) { const controls: { current: HarnessControls | null } = { current: null } runtime.sentIntents = [] runtime.modelChanges = [] + runtime.composerEnterBehavior = composerEnterBehavior render() return controls } @@ -563,6 +568,51 @@ describe('HappyComposer send intent gestures', () => { expect(runtime.pendingSendIntentRef?.current).toBe('default') }) + it('sends with Alt+S regardless of the configured Enter behavior', () => { + renderComposer('shortcut send', null, true, 'newline') + + fireEvent.keyDown(input(), { key: 's', code: 'KeyS', altKey: true }) + + expect(runtime.sentIntents).toEqual(['default']) + expect(runtime.pendingSendIntentRef?.current).toBe('default') + }) + + it('matches the logical S key across keyboard layouts', () => { + renderComposer('shortcut send', null, true) + + fireEvent.keyDown(input(), { key: 's', code: 'KeyO', altKey: true }) + + expect(runtime.sentIntents).toEqual(['default']) + expect(runtime.pendingSendIntentRef?.current).toBe('default') + }) + + it('does not send Alt+S while an IME composition is active', () => { + renderComposer('shortcut send', null, true) + + fireEvent.keyDown(input(), { key: 's', code: 'KeyS', altKey: true, isComposing: true }) + + expect(runtime.sentIntents).toEqual([]) + expect(runtime.pendingSendIntentRef?.current).toBe('default') + }) + + it('does not treat modified Alt+S combinations as the send shortcut', () => { + renderComposer('shortcut send', null, true) + + fireEvent.keyDown(input(), { key: 's', code: 'KeyS', altKey: true, shiftKey: true }) + + expect(runtime.sentIntents).toEqual([]) + expect(runtime.pendingSendIntentRef?.current).toBe('default') + }) + + it('preserves printable Option characters that share the physical S key', () => { + renderComposer('shortcut send', null, true) + + fireEvent.keyDown(input(), { key: 'ß', code: 'KeyS', altKey: true }) + + expect(runtime.sentIntents).toEqual([]) + expect(runtime.pendingSendIntentRef?.current).toBe('default') + }) + it('consumes a restored queue retry mark before resetting the shared ref', () => { renderComposer('retry queue', null, true) runtime.pendingSendIntentRef!.current = 'queue' diff --git a/web/src/components/AssistantChat/HappyComposer.tsx b/web/src/components/AssistantChat/HappyComposer.tsx index 3f6e9cf7..2bf18e57 100644 --- a/web/src/components/AssistantChat/HappyComposer.tsx +++ b/web/src/components/AssistantChat/HappyComposer.tsx @@ -1370,6 +1370,23 @@ export function HappyComposer(props: { return } + // Alt+S is an explicit send shortcut, independent of the Enter setting. + // Match the logical key so keyboard layouts can map Alt+S to another physical key. + const isAltSShortcut = + (e.key === 's' || e.key === 'S') + && e.altKey + && !e.ctrlKey + && !e.metaKey + && !e.shiftKey + if (isAltSShortcut) { + e.preventDefault() + if (canSend) { + flushAndSend() + setShowContinueHint(false) + } + return + } + // Shift+Enter inserts a newline (textarea default; rich path inserts
). if (key === 'Enter' && e.shiftKey) { return