@@ -22,7 +22,7 @@ export type ChatInputProps = {
2222 on_caret_position_change : ( caret_position : number ) => void
2323 is_web_mode : boolean
2424 on_search_click : ( ) => void
25- on_at_sign_click : ( ) => void
25+ on_at_sign_click : ( search_value ?: string ) => void
2626 on_hash_sign_click : ( ) => void
2727 on_curly_braces_click : ( ) => void
2828 caret_position_to_set ?: number
@@ -99,6 +99,32 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
9999 props . is_web_mode
100100 ] )
101101
102+ const custom_handle_key_down = (
103+ e : React . KeyboardEvent < HTMLTextAreaElement >
104+ ) => {
105+ if ( e . key === 'Tab' && ! e . shiftKey ) {
106+ const textarea = e . currentTarget
107+ const value = textarea . value
108+ const selection_start = textarea . selectionStart
109+
110+ if ( selection_start > 0 ) {
111+ const text_before_cursor = value . substring ( 0 , selection_start )
112+ if (
113+ text_before_cursor . trim ( ) !== '' &&
114+ ! / \s $ / . test ( text_before_cursor )
115+ ) {
116+ e . preventDefault ( )
117+ const match = text_before_cursor . match ( / ( \S + ) $ / )
118+ if ( match ) {
119+ props . on_at_sign_click ( match [ 1 ] )
120+ return
121+ }
122+ }
123+ }
124+ }
125+ handle_key_down ( e )
126+ }
127+
102128 return (
103129 < div className = { styles . container } >
104130 { props . has_active_selection && props . is_in_code_completions_mode && (
@@ -146,7 +172,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
146172 placeholder = { placeholder }
147173 value = { props . value }
148174 onChange = { handle_input_change }
149- onKeyDown = { handle_key_down }
175+ onKeyDown = { custom_handle_key_down }
150176 onSelect = { handle_select }
151177 autoFocus
152178 className = { styles . textarea }
@@ -170,7 +196,7 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
170196 } }
171197 >
172198 < button
173- onClick = { props . on_at_sign_click }
199+ onClick = { ( ) => props . on_at_sign_click ( ) }
174200 className = { cn ( styles [ 'footer__left__button' ] ) }
175201 title = "Reference file"
176202 >
0 commit comments