@@ -143,21 +143,36 @@ function setupMonaco() {
143143interface ChatInputProps {
144144 isGlobal : boolean ;
145145 readonly data : DashboardState | null ;
146+ value : string ;
147+ onValueChange : ( value : string ) => void ;
148+ focusTrigger ?: number ; // Increment this to trigger focus
146149}
147150
148- export const ChatInput : React . FC < ChatInputProps > = ( { data, isGlobal } ) => {
149- const [ chatInput , setChatInput ] = useState ( '' ) ;
151+ export const ChatInput : React . FC < ChatInputProps > = ( { data, isGlobal, value, onValueChange, focusTrigger } ) => {
150152 const [ editor , setEditor ] = useState < monaco . editor . IStandaloneCodeEditor | null > ( null ) ;
151153 const [ showDropdown , setShowDropdown ] = useState ( false ) ;
152154
153- // Handle content changes
154- const handleEditorChange = useCallback ( ( value : string | undefined ) => {
155- setChatInput ( value || '' ) ;
156- } , [ ] ) ;
155+ // Focus the editor when focusTrigger changes
156+ useEffect ( ( ) => {
157+ if ( focusTrigger !== undefined && editor ) {
158+ editor . focus ( ) ;
159+ // Position cursor at the end
160+ const model = editor . getModel ( ) ;
161+ if ( model ) {
162+ const position = model . getPositionAt ( value . length ) ;
163+ editor . setPosition ( position ) ;
164+ }
165+ }
166+ } , [ focusTrigger , editor , value ] ) ;
167+
168+ // Handle content changes from the editor
169+ const handleEditorChange = useCallback ( ( newValue : string | undefined ) => {
170+ onValueChange ( newValue || '' ) ;
171+ } , [ onValueChange ] ) ;
157172
158173 const handleAgentClick = useCallback ( ( agent : string ) => {
159174 let finalInput : string ;
160- const currentInput = chatInput . trim ( ) ;
175+ const currentInput = value . trim ( ) ;
161176
162177 if ( ! currentInput ) {
163178 // Empty input - just set the agent
@@ -174,7 +189,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({ data, isGlobal }) => {
174189 }
175190 }
176191
177- setChatInput ( finalInput ) ;
192+ onValueChange ( finalInput ) ;
178193 if ( editor ) {
179194 editor . focus ( ) ;
180195 // Position cursor at the end
@@ -184,28 +199,28 @@ export const ChatInput: React.FC<ChatInputProps> = ({ data, isGlobal }) => {
184199 editor . setPosition ( position ) ;
185200 }
186201 }
187- } , [ chatInput , editor ] ) ;
202+ } , [ value , editor , onValueChange ] ) ;
188203
189204 const handleSendChat = useCallback ( ( ) => {
190- if ( chatInput . trim ( ) ) {
191- const trimmedInput = chatInput . trim ( ) ;
205+ if ( value . trim ( ) ) {
206+ const trimmedInput = value . trim ( ) ;
192207
193208 // Send all chat input to the provider for processing
194209 vscode . postMessage ( {
195210 command : 'submit-chat' ,
196211 args : { query : trimmedInput }
197212 } ) ;
198213
199- setChatInput ( '' ) ;
214+ onValueChange ( '' ) ;
200215 }
201- } , [ chatInput ] ) ;
216+ } , [ value , onValueChange ] ) ;
202217
203218
204219
205220 // Handle dropdown option for planning task with local agent
206221 const handlePlanWithLocalAgent = useCallback ( ( ) => {
207- if ( chatInput . trim ( ) ) {
208- const trimmedInput = chatInput . trim ( ) ;
222+ if ( value . trim ( ) ) {
223+ const trimmedInput = value . trim ( ) ;
209224 // Remove @copilot prefix for planning with local agent
210225 const cleanQuery = trimmedInput . replace ( / @ c o p i l o t \s * / , '' ) . trim ( ) ;
211226
@@ -215,10 +230,10 @@ export const ChatInput: React.FC<ChatInputProps> = ({ data, isGlobal }) => {
215230 args : { query : cleanQuery }
216231 } ) ;
217232
218- setChatInput ( '' ) ;
233+ onValueChange ( '' ) ;
219234 setShowDropdown ( false ) ;
220235 }
221- } , [ chatInput ] ) ;
236+ } , [ value , onValueChange ] ) ;
222237
223238 // Handle clicking outside dropdown to close it
224239 useEffect ( ( ) => {
@@ -287,7 +302,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({ data, isGlobal }) => {
287302 < Editor
288303 key = "task-input-editor"
289304 defaultLanguage = "taskInput"
290- value = { chatInput }
305+ value = { value }
291306 theme = "taskInputTheme"
292307 loading = { null }
293308 onMount = { handleEditorDidMount }
@@ -322,12 +337,12 @@ export const ChatInput: React.FC<ChatInputProps> = ({ data, isGlobal }) => {
322337 automaticLayout : true
323338 } }
324339 />
325- { isCopilotCommand ( chatInput ) ? (
340+ { isCopilotCommand ( value ) ? (
326341 < div className = "send-button-container" >
327342 < button
328343 className = "send-button-inline split-left"
329344 onClick = { handleSendChat }
330- disabled = { ! chatInput . trim ( ) }
345+ disabled = { ! value . trim ( ) }
331346 title = "Start new remote Copilot task (Ctrl+Enter)"
332347 >
333348 < span style = { { marginRight : '4px' , fontSize : '12px' } } > Start remote task</ span >
@@ -339,7 +354,7 @@ export const ChatInput: React.FC<ChatInputProps> = ({ data, isGlobal }) => {
339354 e . stopPropagation ( ) ;
340355 setShowDropdown ( ! showDropdown ) ;
341356 } }
342- disabled = { ! chatInput . trim ( ) }
357+ disabled = { ! value . trim ( ) }
343358 title = "More options"
344359 >
345360 < span className = "codicon codicon-chevron-down" > </ span >
@@ -360,15 +375,15 @@ export const ChatInput: React.FC<ChatInputProps> = ({ data, isGlobal }) => {
360375 < button
361376 className = "send-button-inline"
362377 onClick = { handleSendChat }
363- disabled = { ! chatInput . trim ( ) }
378+ disabled = { ! value . trim ( ) }
364379 title = {
365- isLocalCommand ( chatInput )
380+ isLocalCommand ( value )
366381 ? 'Start new local task (Ctrl+Enter)'
367382 : 'Send message (Ctrl+Enter)'
368383 }
369384 >
370385 < span style = { { marginRight : '4px' , fontSize : '12px' } } >
371- { isLocalCommand ( chatInput )
386+ { isLocalCommand ( value )
372387 ? 'Start local task'
373388 : 'Send'
374389 }
0 commit comments