@@ -7,12 +7,15 @@ import { useShallow } from "zustand/react/shallow";
77import { FileSearch } from "./FileSearch.js" ;
88import { runTool } from "@/agent/tools/index.js" ;
99
10+ const MAX_VISIBLE_FILES = 5 ;
11+
1012export function UserInput ( ) {
1113 const [ useStateInput , setInputValue ] = useState ( "" ) ;
1214 const [ searchActive , setSearchActive ] = useState ( false ) ;
1315 const [ searchQuery , setSearchQuery ] = useState ( "" ) ;
1416 const [ searchResults , setSearchResults ] = useState < string [ ] > ( [ ] ) ;
1517 const [ selectedIndex , setSelectedIndex ] = useState ( 0 ) ;
18+ const [ visibleFileCount , setVisibleFileCount ] = useState ( MAX_VISIBLE_FILES ) ;
1619
1720 const {
1821 startAgent,
@@ -60,6 +63,7 @@ export function UserInput() {
6063 setSearchActive ( true ) ;
6164 setSearchQuery ( query ) ;
6265 setSelectedIndex ( 0 ) ;
66+ setVisibleFileCount ( MAX_VISIBLE_FILES ) ;
6367 } else {
6468 setSearchActive ( false ) ;
6569 }
@@ -90,7 +94,13 @@ export function UserInput() {
9094 if ( key . upArrow ) {
9195 setSelectedIndex ( ( prev ) => ( prev > 0 ? prev - 1 : prev ) ) ;
9296 } else if ( key . downArrow ) {
93- setSelectedIndex ( ( prev ) => ( prev < searchResults . length - 1 ? prev + 1 : prev ) ) ;
97+ setSelectedIndex ( ( prev ) => {
98+ const newIndex = prev + 1 ;
99+ if ( newIndex >= visibleFileCount && newIndex < searchResults . length ) {
100+ setVisibleFileCount ( ( prevCount ) => prevCount + 1 ) ;
101+ }
102+ return newIndex < searchResults . length ? newIndex : prev ;
103+ } ) ;
94104 }
95105 } else if ( ! isThinking ) {
96106 if ( key . upArrow ) {
@@ -107,7 +117,7 @@ export function UserInput() {
107117 }
108118 } ) ;
109119
110- const handleSubmit = ( ) => {
120+ const handleSubmit = async ( ) => {
111121 const value = useStateInput . trim ( ) ;
112122
113123 if ( value === "/help" ) {
@@ -128,10 +138,21 @@ export function UserInput() {
128138 const lastAtIndex = useStateInput . lastIndexOf ( "@" ) ;
129139 const file = searchResults [ selectedIndex ] ;
130140 if ( file ) {
131- const newValue = `${ useStateInput . slice ( 0 , lastAtIndex ) } @${ file } ` ;
132- setInputValue ( newValue ) ;
133- setSearchActive ( false ) ;
134- setSearchResults ( [ ] ) ;
141+ try {
142+ const content = await runTool (
143+ { toolName : "readFile" , args : { path : file } } ,
144+ config ! ,
145+ ) ;
146+ const fileBlock = `File: ${ file } \n\n${ content } ` ;
147+ const newValue = `${ useStateInput . slice ( 0 , lastAtIndex ) } ${ fileBlock } ` ;
148+ setInputValue ( newValue ) ;
149+ } catch ( error ) {
150+ const newValue = `${ useStateInput . slice ( 0 , lastAtIndex ) } @${ file } ` ;
151+ setInputValue ( newValue ) ;
152+ } finally {
153+ setSearchActive ( false ) ;
154+ setSearchResults ( [ ] ) ;
155+ }
135156 }
136157 return ;
137158 }
@@ -178,12 +199,15 @@ export function UserInput() {
178199 }
179200 } ;
180201
202+ const visibleFiles = searchResults . slice ( 0 , visibleFileCount ) ;
203+
181204 return (
182205 < Box flexDirection = "column" >
183206 { searchActive && searchResults . length > 0 && (
184207 < FileSearch
185208 query = { searchQuery }
186- files = { searchResults }
209+ visibleFiles = { visibleFiles }
210+ totalFiles = { searchResults . length }
187211 selectedIndex = { selectedIndex }
188212 />
189213 ) }
0 commit comments