11import { TextInput } from '@inkjs/ui' ;
2- import { Box , Text } from 'ink' ;
2+ import { Box , Text , useApp , useInput } from 'ink' ;
33import { useCallback , useState } from 'react' ;
44
55import { COMMAND , UI } from '../../constants' ;
@@ -17,8 +17,13 @@ function hasActiveMentionQuery(input: string): boolean {
1717}
1818
1919export function Input ( { isDisabled = false , onSubmit } : Props ) {
20+ const { exit } = useApp ( ) ;
2021 const [ input , setInput ] = useState ( '' ) ;
21- const [ resetKey , setResetKey ] = useState ( 0 ) ;
22+ const [ inputKey , setInputKey ] = useState ( 0 ) ;
23+
24+ const remountTextInput = useCallback ( ( ) => {
25+ setInputKey ( ( key ) => key + 1 ) ;
26+ } , [ setInputKey ] ) ;
2227
2328 const handleSubmitText = useCallback (
2429 async ( input : string ) => {
@@ -35,9 +40,9 @@ export function Input({ isDisabled = false, onSubmit }: Props) {
3540
3641 onSubmit ( trimmedInput ) ;
3742 setInput ( '' ) ;
38- setResetKey ( ( key ) => key + 1 ) ;
43+ remountTextInput ( ) ;
3944 } ,
40- [ onSubmit ] ,
45+ [ onSubmit , remountTextInput ] ,
4146 ) ;
4247
4348 const handleSubmitCommand = useCallback (
@@ -48,15 +53,29 @@ export function Input({ isDisabled = false, onSubmit }: Props) {
4853
4954 onSubmit ( input ) ;
5055 setInput ( '' ) ;
51- setResetKey ( ( key ) => key + 1 ) ;
56+ remountTextInput ( ) ;
5257 } ,
53- [ onSubmit ] ,
58+ [ onSubmit , remountTextInput ] ,
5459 ) ;
5560
56- const handleSelectFileSuggestion = useCallback ( ( nextInput : string ) => {
57- setInput ( nextInput ) ;
58- setResetKey ( ( key ) => key + 1 ) ;
59- } , [ ] ) ;
61+ const handleSelectFileSuggestion = useCallback (
62+ ( nextInput : string ) => {
63+ setInput ( nextInput ) ;
64+ remountTextInput ( ) ;
65+ } ,
66+ [ remountTextInput ] ,
67+ ) ;
68+
69+ useInput ( ( _input , key ) => {
70+ if ( key . ctrl && _input === 'c' ) {
71+ if ( input ) {
72+ setInput ( '' ) ;
73+ remountTextInput ( ) ;
74+ } else {
75+ exit ( ) ;
76+ }
77+ }
78+ } ) ;
6079
6180 const showCommandMenu = input . startsWith ( '/' ) ;
6281 const showFileSuggestions = ! showCommandMenu && hasActiveMentionQuery ( input ) ;
@@ -69,7 +88,7 @@ export function Input({ isDisabled = false, onSubmit }: Props) {
6988 < TextInput
7089 defaultValue = { input }
7190 isDisabled = { isDisabled }
72- key = { resetKey }
91+ key = { inputKey }
7392 onChange = { setInput }
7493 // eslint-disable-next-line @typescript-eslint/no-misused-promises
7594 onSubmit = { handleSubmitText }
0 commit comments