Skip to content

Commit 9912876

Browse files
committed
feat(cli): add escape key handler to exit input modes
Pressing escape with empty input now exits current mode (usage/referral) back to default mode. Use input mode config to control slash suggestions.
1 parent c80efb1 commit 9912876

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

cli/src/chat.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { useTheme } from './hooks/use-theme'
4040
import { useTimeout } from './hooks/use-timeout'
4141

4242
import { useChatStore } from './state/chat-store'
43+
import { getInputModeConfig } from './utils/input-modes'
4344
import { useFeedbackStore } from './state/feedback-store'
4445
import { createChatScrollAcceleration } from './utils/chat-scroll-accel'
4546
import { loadLocalAgents } from './utils/local-agent-registry'
@@ -885,10 +886,11 @@ export const Chat = ({
885886
[messages],
886887
)
887888

889+
const modeConfig = getInputModeConfig(inputMode)
888890
const hasSlashSuggestions =
889891
slashContext.active &&
890892
slashSuggestionItems.length > 0 &&
891-
inputMode === 'default'
893+
!modeConfig.disableSlashSuggestions
892894
const hasMentionSuggestions =
893895
!slashContext.active &&
894896
mentionContext.active &&

cli/src/hooks/use-keyboard-handlers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useKeyboard } from '@opentui/react'
22
import { useCallback } from 'react'
33

4+
import { useChatStore } from '../state/chat-store'
5+
46
type InputHandle = { focus: () => void }
57

68
interface KeyboardHandlersConfig {
@@ -62,6 +64,21 @@ export const useKeyboardHandlers = ({
6264
return
6365
}
6466

67+
// Handle escape with empty input: exit current mode if not default
68+
if (isEscape && !isStreaming && !isWaitingForResponse && !inputValue.trim()) {
69+
const { inputMode, setInputMode } = useChatStore.getState()
70+
if (inputMode !== 'default') {
71+
if (
72+
'preventDefault' in key &&
73+
typeof key.preventDefault === 'function'
74+
) {
75+
key.preventDefault()
76+
}
77+
setInputMode('default')
78+
return
79+
}
80+
}
81+
6582
if ((isEscape || isCtrlC) && (isStreaming || isWaitingForResponse)) {
6683
if (
6784
'preventDefault' in key &&

0 commit comments

Comments
 (0)