@@ -76,7 +76,12 @@ export function InputRow({
7676 } else if ( event . key === "Tab" && ! event . shiftKey && ! event . ctrlKey && ! event . metaKey && ! event . altKey ) {
7777 event . preventDefault ( ) ;
7878 if ( inputRef . current != null && autocompleteText !== "" ) {
79- setInputValue ( inputRef . current . value + autocompleteText ) ;
79+ const newlineIndex = autocompleteText . indexOf ( "\n" ) ;
80+ const textToAccept = newlineIndex <= 0
81+ ? autocompleteText
82+ : autocompleteText . slice ( 0 , newlineIndex ) ;
83+
84+ setInputValue ( inputRef . current . value + textToAccept ) ;
8085 inputRef . current . scrollTop = inputRef . current . scrollHeight ;
8186 onPromptInput ?.( inputRef . current . value ) ;
8287 }
@@ -85,6 +90,14 @@ export function InputRow({
8590 }
8691 } , [ submitPrompt , setInputValue , onPromptInput , resizeInput , autocompleteText ] ) ;
8792
93+ const previewAutocompleteText = useMemo ( ( ) => {
94+ const lines = autocompleteText . split ( "\n" ) ;
95+ if ( lines . length <= 1 || lines [ 1 ] ! . trim ( ) === "" )
96+ return lines [ 0 ] ! ;
97+
98+ return autocompleteText ;
99+ } , [ autocompleteText ] ) ;
100+
88101 return < div className = { classNames ( "appInputRow" , disabled && "disabled" ) } >
89102 < div className = "inputContainer" >
90103 < textarea
@@ -105,7 +118,7 @@ export function InputRow({
105118 < div className = "autocomplete" ref = { autocompleteRef } >
106119 < div className = { classNames ( "content" , autocompleteText === "" && "hide" ) } >
107120 < div className = "currentText" ref = { autocompleteCurrentTextRef } />
108- < div className = "completion" > { autocompleteText } </ div >
121+ < div className = "completion" > { previewAutocompleteText } </ div >
109122 < div className = "pressTab" > Tab</ div >
110123 </ div >
111124 </ div >
0 commit comments