@@ -74,6 +74,16 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
7474 pinnedApiConfigs,
7575 togglePinnedApiConfig,
7676 } = useExtensionState ( )
77+
78+ // Find the ID and display text for the currently selected API configuration
79+ const { currentConfigId, displayName } = useMemo ( ( ) => {
80+ const currentConfig = listApiConfigMeta ?. find ( ( config ) => config . name === currentApiConfigName )
81+ return {
82+ currentConfigId : currentConfig ?. id || "" ,
83+ displayName : currentApiConfigName || "" , // Use the name directly for display
84+ }
85+ } , [ listApiConfigMeta , currentApiConfigName ] )
86+
7787 const [ gitCommits , setGitCommits ] = useState < any [ ] > ( [ ] )
7888 const [ showDropdown , setShowDropdown ] = useState ( false )
7989 const [ fileSearchResults , setFileSearchResults ] = useState < SearchResult [ ] > ( [ ] )
@@ -964,23 +974,26 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
964974 { /* API configuration selector - flexible width */ }
965975 < div className = { cn ( "flex-1" , "min-w-0" , "overflow-hidden" ) } >
966976 < SelectDropdown
967- value = { currentApiConfigName || "" }
977+ value = { currentConfigId }
968978 disabled = { textAreaDisabled }
969979 title = { t ( "chat:selectApiConfig" ) }
980+ placeholder = { displayName } // Always show the current name
970981 options = { [
971982 // Pinned items first
972983 ...( listApiConfigMeta || [ ] )
973- . filter ( ( config ) => pinnedApiConfigs && pinnedApiConfigs [ config . name ] )
984+ . filter ( ( config ) => pinnedApiConfigs && pinnedApiConfigs [ config . id ] )
974985 . map ( ( config ) => ( {
975- value : config . name ,
986+ value : config . id ,
976987 label : config . name ,
988+ name : config . name , // Keep name for comparison with currentApiConfigName
977989 type : DropdownOptionType . ITEM ,
978990 pinned : true ,
979- } ) ) ,
991+ } ) )
992+ . sort ( ( a , b ) => a . label . localeCompare ( b . label ) ) ,
980993 // If we have pinned items and unpinned items, add a separator
981994 ...( pinnedApiConfigs &&
982995 Object . keys ( pinnedApiConfigs ) . length > 0 &&
983- ( listApiConfigMeta || [ ] ) . some ( ( config ) => ! pinnedApiConfigs [ config . name ] )
996+ ( listApiConfigMeta || [ ] ) . some ( ( config ) => ! pinnedApiConfigs [ config . id ] )
984997 ? [
985998 {
986999 value : "sep-pinned" ,
@@ -991,10 +1004,11 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
9911004 : [ ] ) ,
9921005 // Unpinned items sorted alphabetically
9931006 ...( listApiConfigMeta || [ ] )
994- . filter ( ( config ) => ! pinnedApiConfigs || ! pinnedApiConfigs [ config . name ] )
1007+ . filter ( ( config ) => ! pinnedApiConfigs || ! pinnedApiConfigs [ config . id ] )
9951008 . map ( ( config ) => ( {
996- value : config . name ,
1009+ value : config . id ,
9971010 label : config . name ,
1011+ name : config . name , // Keep name for comparison with currentApiConfigName
9981012 type : DropdownOptionType . ITEM ,
9991013 pinned : false ,
10001014 } ) )
@@ -1010,14 +1024,32 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
10101024 type : DropdownOptionType . ACTION ,
10111025 } ,
10121026 ] }
1013- onChange = { ( value ) => vscode . postMessage ( { type : "loadApiConfiguration" , text : value } ) }
1027+ onChange = { ( value ) => {
1028+ if ( value === "settingsButtonClicked" ) {
1029+ // Handle special actions
1030+ vscode . postMessage ( {
1031+ type : "loadApiConfiguration" ,
1032+ text : value ,
1033+ } )
1034+ } else {
1035+ // Use the ID directly with our new message type
1036+ vscode . postMessage ( {
1037+ type : "loadApiConfigurationById" ,
1038+ text : value ,
1039+ } )
1040+ }
1041+ } }
10141042 contentClassName = "max-h-[300px] overflow-y-auto"
10151043 triggerClassName = "w-full text-ellipsis overflow-hidden"
10161044 renderItem = { ( option ) => {
10171045 if ( option . type !== DropdownOptionType . ITEM ) {
10181046 return option . label
10191047 }
10201048
1049+ // Get the config from listApiConfigMeta by ID
1050+ const config = listApiConfigMeta ?. find ( ( c ) => c . id === option . value )
1051+ const isCurrentConfig = config ?. name === currentApiConfigName
1052+
10211053 return (
10221054 < div className = "flex items-center justify-between w-full" >
10231055 < span > { option . label } </ span >
@@ -1033,15 +1065,13 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
10331065 togglePinnedApiConfig ( option . value )
10341066 vscode . postMessage ( {
10351067 type : "toggleApiConfigPin" ,
1036- text : option . value ,
1068+ text : option . value , // Send ID as text
10371069 } )
10381070 } }
10391071 title = { option . pinned ? t ( "chat:unpin" ) : t ( "chat:pin" ) } >
10401072 < Pin className = "size-3" />
10411073 </ div >
1042- { option . value === currentApiConfigName && (
1043- < Check className = "size-4 p-0.5 ml-1" />
1044- ) }
1074+ { isCurrentConfig && < Check className = "size-4 p-0.5 ml-1" /> }
10451075 </ div >
10461076 )
10471077 } }
0 commit comments