mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-25 05:07:05 +00:00
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
This commit is contained in:
@@ -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<void> | 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(<ComposerHarness initialText={initialText} initialSchedule={initialSchedule} piRunning={piRunning} controls={controls} />)
|
||||
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'
|
||||
|
||||
@@ -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 <br>).
|
||||
if (key === 'Enter' && e.shiftKey) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user