mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(ui): app-wide keyboard shortcuts with TUI keybind import
This commit is contained in:
1 parent
b18e4f13b3
commit
b06de60f6b
38 files changed
+2467
-440
No files matched your search
@@ -422,6 +422,30 @@ describe('PromptInput command submission', () => {
|
||||
expect(screen.getByTestId('model-quick-select')).toHaveAttribute('data-open', 'true')
|
||||
})
|
||||
|
||||
it('resets bash mode through the imperative clearPrompt', async () => {
|
||||
const queryClient = createTestQueryClient()
|
||||
queryClient.setQueryData(['opencode', 'session', 'test-session', '/test'], sessionInfo())
|
||||
const ref = createRef<PromptInputHandle>()
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<PromptInput {...defaultProps} ref={ref} />
|
||||
</QueryClientProvider>
|
||||
)
|
||||
|
||||
const input = await screen.findByPlaceholderText('Send a message...')
|
||||
fireEvent.change(input, { target: { value: '!' } })
|
||||
expect(input).toHaveValue('!')
|
||||
expect(screen.getByTestId('composer-mode-badge')).toHaveTextContent('BASH')
|
||||
|
||||
act(() => {
|
||||
ref.current?.clearPrompt()
|
||||
})
|
||||
|
||||
expect(input).toHaveValue('')
|
||||
expect(screen.queryByTestId('composer-mode-badge')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps attachments and clears only the text when a built-in command is submitted', async () => {
|
||||
const { container } = renderComponent()
|
||||
|
||||
|
||||
@@ -110,6 +110,8 @@ export interface PromptInputHandle {
|
||||
clearPrompt: () => void
|
||||
triggerFileUpload: () => void
|
||||
openModelPicker: () => void
|
||||
cycleAgent: () => void
|
||||
cycleVariant: () => void
|
||||
}
|
||||
|
||||
interface PromptInputProps {
|
||||
@@ -243,29 +245,6 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
|
||||
fileInputRef.current?.click()
|
||||
}, [])
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
setPromptValue: (value: string) => {
|
||||
setPrompt(value)
|
||||
textareaRef.current?.focus()
|
||||
},
|
||||
clearPrompt: () => {
|
||||
setPrompt('')
|
||||
setAttachedFiles(new Map())
|
||||
revokeBlobUrls(imageAttachments)
|
||||
setImageAttachments([])
|
||||
resetVoiceGestureState()
|
||||
if (isRecording) {
|
||||
abortRecording()
|
||||
} else {
|
||||
clearSTT()
|
||||
}
|
||||
textareaRef.current?.focus()
|
||||
},
|
||||
triggerFileUpload: openFilePicker,
|
||||
openModelPicker: () => {
|
||||
setIsModelPickerOpen(true)
|
||||
}
|
||||
}), [imageAttachments, clearSTT, isRecording, abortRecording, resetVoiceGestureState, openFilePicker])
|
||||
const sessionAgent = useSessionAgent(sessionID, directory)
|
||||
const currentMode = localMode ?? sessionAgent.agent
|
||||
const setStoredAgent = useSessionAgentStore((s) => s.setAgent)
|
||||
@@ -1090,16 +1069,13 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
textareaRef.current?.blur()
|
||||
}
|
||||
handleSubmit()
|
||||
} else if (e.key === 'Escape') {
|
||||
} else if (e.key === 'Escape' && !isSessionActive) {
|
||||
closeSuggestions()
|
||||
setPrompt('')
|
||||
revokeBlobUrls(imageAttachments)
|
||||
setImageAttachments([])
|
||||
resetVoiceGestureState()
|
||||
clearSTT()
|
||||
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 't') {
|
||||
e.preventDefault()
|
||||
handleCycleVariant()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,13 +1101,13 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
updateSuggestionTriggers(value, e.target.selectionStart)
|
||||
}
|
||||
|
||||
const closeSuggestions = () => {
|
||||
const closeSuggestions = useCallback(() => {
|
||||
setShowSuggestions(false)
|
||||
setSuggestionQuery('')
|
||||
setShowMentionSuggestions(false)
|
||||
setMentionQuery('')
|
||||
setMentionRange(null)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const updateSuggestionTriggers = (value: string, cursorPosition: number) => {
|
||||
const mentionTrigger = detectMentionTrigger(value, cursorPosition)
|
||||
@@ -1290,6 +1266,34 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
|
||||
handleAgentChange(next)
|
||||
}, [agents, currentMode, handleAgentChange])
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
setPromptValue: (value: string) => {
|
||||
setPrompt(value)
|
||||
textareaRef.current?.focus()
|
||||
},
|
||||
clearPrompt: () => {
|
||||
setPrompt('')
|
||||
setAttachedFiles(new Map())
|
||||
revokeBlobUrls(imageAttachments)
|
||||
setImageAttachments([])
|
||||
closeSuggestions()
|
||||
setIsBashMode(false)
|
||||
resetVoiceGestureState()
|
||||
if (isRecording) {
|
||||
abortRecording()
|
||||
} else {
|
||||
clearSTT()
|
||||
}
|
||||
textareaRef.current?.focus()
|
||||
},
|
||||
triggerFileUpload: openFilePicker,
|
||||
openModelPicker: () => {
|
||||
setIsModelPickerOpen(true)
|
||||
},
|
||||
cycleAgent: handleCycleAgent,
|
||||
cycleVariant: handleCycleVariant,
|
||||
}), [imageAttachments, clearSTT, isRecording, abortRecording, resetVoiceGestureState, closeSuggestions, openFilePicker, handleCycleAgent, handleCycleVariant])
|
||||
|
||||
const commandActionsWithPrompt = useMemo<CommandActions>(
|
||||
() => ({
|
||||
...commandActions,
|
||||
@@ -1466,6 +1470,7 @@ return (
|
||||
)}
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
data-prompt-input
|
||||
value={prompt}
|
||||
onChange={handleInput}
|
||||
onFocus={handlePromptFocus}
|
||||
|
||||
Reference in new issue
Block a user