mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(shortcuts): rework shortcut bindings, focus restore, and input guards
Resolve effective bindings from stored prefs plus defaults with leader/direct collision handling and default leader Ctrl+X; let direct actions pass through in terminals and suppress abort while an overlay is open. Add half-page scroll disengage, verified overlay focus restore, and consolidate prompt reset.
This commit is contained in:
1 parent
7e8443f54f
commit
994a8b82e8
33 files changed
+784
-195
No files matched your search
@@ -1,9 +1,24 @@
|
||||
import { render, screen, waitFor, within } from '@testing-library/react'
|
||||
import { render as renderRaw, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { ReactElement } from 'react'
|
||||
import type { FormInfo } from '@opencode-manager/shared/opencode'
|
||||
import { KeyboardShortcutsProvider, useShortcutActions } from '@/contexts/KeyboardShortcutsContext'
|
||||
import { FormPrompt } from './FormPrompt'
|
||||
|
||||
vi.mock('@/hooks/useSettings', () => ({
|
||||
useSettings: () => ({ preferences: undefined }),
|
||||
}))
|
||||
|
||||
function render(ui: ReactElement) {
|
||||
return renderRaw(ui, { wrapper: KeyboardShortcutsProvider })
|
||||
}
|
||||
|
||||
function AbortLayer({ onAbort }: { onAbort: () => void }) {
|
||||
useShortcutActions({ abort: onAbort })
|
||||
return null
|
||||
}
|
||||
|
||||
const selectForm: FormInfo = {
|
||||
id: 'form-1',
|
||||
sessionID: 'session-1',
|
||||
@@ -612,4 +627,22 @@ describe('FormPrompt', () => {
|
||||
expect(screen.queryByRole('link', { name: /Approve access/ })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('keyboard shortcuts', () => {
|
||||
it('minimizes once on Escape while expanded without triggering a registered session abort', async () => {
|
||||
const sessionAbort = vi.fn()
|
||||
const onMinimize = vi.fn()
|
||||
render(
|
||||
<>
|
||||
<AbortLayer onAbort={sessionAbort} />
|
||||
<FormPrompt form={selectForm} onReply={vi.fn()} onCancel={vi.fn()} onMinimize={onMinimize} />
|
||||
</>
|
||||
)
|
||||
|
||||
await userEvent.keyboard('{Escape}')
|
||||
|
||||
expect(onMinimize).toHaveBeenCalledTimes(1)
|
||||
expect(sessionAbort).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -7,6 +7,7 @@ import type { FormAnswer, FormField, FormInfo } from '@opencode-manager/shared/o
|
||||
import { buildAnswer, hasMissingAnswers, visibleFields } from '@/lib/formFields'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { useShortcutActions } from '@/contexts/KeyboardShortcutsContext'
|
||||
|
||||
type AnswerableFormField = Exclude<FormField, { type: 'external' }>
|
||||
|
||||
@@ -136,6 +137,10 @@ export function FormPrompt({ form, onReply, onCancel, onMinimize }: FormPromptPr
|
||||
onMinimize?.()
|
||||
}
|
||||
|
||||
useShortcutActions({
|
||||
abort: !isMinimized && !expandedCustom ? handleMinimize : undefined,
|
||||
})
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!canSubmit) return
|
||||
setIsSubmitting(true)
|
||||
@@ -161,6 +166,7 @@ export function FormPrompt({ form, onReply, onCancel, onMinimize }: FormPromptPr
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.defaultPrevented) return
|
||||
if (e.key === 'Escape' && !isMinimized && !expandedCustom) {
|
||||
setIsMinimized(true)
|
||||
onMinimize?.()
|
||||
|
||||
Reference in new issue
Block a user