@@ -52,6 +52,8 @@ export type PromptFieldProps = {
5252 edit_format_instructions ?: Record < EditFormat , string >
5353 context_file_paths ?: string [ ]
5454 currently_open_file_text ?: string
55+ invocation_count : number
56+ on_invocation_count_change : ( count : number ) => void
5557 on_go_to_file ?: ( file_path : string ) => void
5658}
5759
@@ -62,6 +64,8 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
6264 const [ show_submit_tooltip , set_show_submit_tooltip ] = useState ( false )
6365 const [ is_text_selecting , set_is_text_selecting ] = useState ( false )
6466 const [ is_focused , set_is_focused ] = useState ( false )
67+ const [ is_invocation_dropdown_open , set_is_invocation_dropdown_open ] =
68+ useState ( false )
6569 const [ hovered_edit_format , set_hovered_edit_format ] =
6670 useState < EditFormat | null > ( null )
6771 const { is_alt_pressed, handle_container_key_down } = use_keyboard_shortcuts ( {
@@ -73,10 +77,12 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
7377 const {
7478 is_dropdown_open,
7579 toggle_dropdown,
80+ close_dropdown,
7681 dropdown_ref,
7782 handle_copy_click,
7883 handle_select_click
7984 } = use_dropdown ( props )
85+ const invocation_dropdown_ref = useRef < HTMLDivElement > ( null )
8086 const { ghost_text, handle_accept_ghost_text } = use_ghost_text ( {
8187 value : props . value ,
8288 input_ref,
@@ -207,6 +213,26 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
207213 }
208214 } , [ props . focus_key ] )
209215
216+ useEffect ( ( ) => {
217+ if ( input_ref . current ) {
218+ const handle_click_outside = ( event : MouseEvent ) => {
219+ if (
220+ invocation_dropdown_ref . current &&
221+ ! invocation_dropdown_ref . current . contains ( event . target as Node )
222+ ) {
223+ set_is_invocation_dropdown_open ( false )
224+ }
225+ }
226+
227+ if ( is_invocation_dropdown_open ) {
228+ document . addEventListener ( 'mousedown' , handle_click_outside )
229+ }
230+ return ( ) => {
231+ document . removeEventListener ( 'mousedown' , handle_click_outside )
232+ }
233+ }
234+ } , [ is_invocation_dropdown_open ] )
235+
210236 useEffect ( ( ) => {
211237 if ( input_ref . current ) {
212238 input_ref . current . focus ( )
@@ -493,6 +519,37 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
493519 { ( ! props . is_web_mode ||
494520 ( props . is_web_mode && props . is_connected ) ) && (
495521 < >
522+ < div
523+ className = { styles [ 'footer__right__invocation-count' ] }
524+ ref = { invocation_dropdown_ref }
525+ >
526+ < button
527+ className = { cn (
528+ styles [ 'footer__right__submit__button' ] ,
529+ styles [ 'footer__right__invocation-count__button' ]
530+ ) }
531+ onClick = { ( e ) => {
532+ e . stopPropagation ( )
533+ set_is_invocation_dropdown_open ( ( prev ) => ! prev )
534+ close_dropdown ( )
535+ } }
536+ title = "Invocation count"
537+ >
538+ { props . invocation_count } ×
539+ </ button >
540+ { is_invocation_dropdown_open && (
541+ < DropdownMenu
542+ items = { [ 1 , 2 , 3 , 4 , 5 ] . map ( ( count ) => ( {
543+ label : `${ count } ×` ,
544+ checked : count == props . invocation_count ,
545+ on_click : ( ) => {
546+ props . on_invocation_count_change ( count )
547+ set_is_invocation_dropdown_open ( false )
548+ }
549+ } ) ) }
550+ />
551+ ) }
552+ </ div >
496553 < button
497554 className = { cn (
498555 styles [ 'footer__right__submit__button' ] ,
@@ -509,7 +566,10 @@ export const PromptField: React.FC<PromptFieldProps> = (props) => {
509566 styles [ 'footer__right__submit__button' ] ,
510567 styles [ 'footer__right__submit__button--chevron' ]
511568 ) }
512- onClick = { toggle_dropdown }
569+ onClick = { ( ) => {
570+ toggle_dropdown ( )
571+ set_is_invocation_dropdown_open ( false )
572+ } }
513573 title = "More actions"
514574 >
515575 < span
0 commit comments