@@ -24,7 +24,7 @@ import { SelectDropdown, DropdownOptionType, Button } from "@/components/ui"
2424import Thumbnails from "../common/Thumbnails"
2525import { MAX_IMAGES_PER_MESSAGE } from "./ChatView"
2626import ContextMenu from "./ContextMenu"
27- import { VolumeX } from "lucide-react"
27+ import { VolumeX , Pin , Check } from "lucide-react"
2828import { IconButton } from "./IconButton"
2929import { cn } from "@/lib/utils"
3030
@@ -64,7 +64,16 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
6464 ref ,
6565 ) => {
6666 const { t } = useAppTranslation ( )
67- const { filePaths, openedTabs, currentApiConfigName, listApiConfigMeta, customModes, cwd } = useExtensionState ( )
67+ const {
68+ filePaths,
69+ openedTabs,
70+ currentApiConfigName,
71+ listApiConfigMeta,
72+ customModes,
73+ cwd,
74+ pinnedApiConfigs,
75+ togglePinnedApiConfig,
76+ } = useExtensionState ( )
6877 const [ gitCommits , setGitCommits ] = useState < any [ ] > ( [ ] )
6978 const [ showDropdown , setShowDropdown ] = useState ( false )
7079 const [ fileSearchResults , setFileSearchResults ] = useState < SearchResult [ ] > ( [ ] )
@@ -959,11 +968,37 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
959968 disabled = { textAreaDisabled }
960969 title = { t ( "chat:selectApiConfig" ) }
961970 options = { [
962- ...( listApiConfigMeta || [ ] ) . map ( ( config ) => ( {
963- value : config . name ,
964- label : config . name ,
965- type : DropdownOptionType . ITEM ,
966- } ) ) ,
971+ // Pinned items first
972+ ...( listApiConfigMeta || [ ] )
973+ . filter ( ( config ) => pinnedApiConfigs && pinnedApiConfigs [ config . name ] )
974+ . map ( ( config ) => ( {
975+ value : config . name ,
976+ label : config . name ,
977+ type : DropdownOptionType . ITEM ,
978+ pinned : true ,
979+ } ) ) ,
980+ // If we have pinned items and unpinned items, add a separator
981+ ...( pinnedApiConfigs &&
982+ Object . keys ( pinnedApiConfigs ) . length > 0 &&
983+ ( listApiConfigMeta || [ ] ) . some ( ( config ) => ! pinnedApiConfigs [ config . name ] )
984+ ? [
985+ {
986+ value : "sep-pinned" ,
987+ label : t ( "chat:separator" ) ,
988+ type : DropdownOptionType . SEPARATOR ,
989+ } ,
990+ ]
991+ : [ ] ) ,
992+ // Unpinned items sorted alphabetically
993+ ...( listApiConfigMeta || [ ] )
994+ . filter ( ( config ) => ! pinnedApiConfigs || ! pinnedApiConfigs [ config . name ] )
995+ . map ( ( config ) => ( {
996+ value : config . name ,
997+ label : config . name ,
998+ type : DropdownOptionType . ITEM ,
999+ pinned : false ,
1000+ } ) )
1001+ . sort ( ( a , b ) => a . label . localeCompare ( b . label ) ) ,
9671002 {
9681003 value : "sep-2" ,
9691004 label : t ( "chat:separator" ) ,
@@ -978,6 +1013,38 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
9781013 onChange = { ( value ) => vscode . postMessage ( { type : "loadApiConfiguration" , text : value } ) }
9791014 contentClassName = "max-h-[300px] overflow-y-auto"
9801015 triggerClassName = "w-full text-ellipsis overflow-hidden"
1016+ renderItem = { ( option ) => {
1017+ if ( option . type !== DropdownOptionType . ITEM ) {
1018+ return option . label
1019+ }
1020+
1021+ return (
1022+ < div className = "flex items-center justify-between w-full" >
1023+ < span > { option . label } </ span >
1024+ < div
1025+ className = { cn (
1026+ "ml-2 p-1 rounded-sm cursor-pointer hover:bg-[rgba(255,255,255,0.1)]" ,
1027+ option . pinned
1028+ ? "text-vscode-focusBorder"
1029+ : "text-vscode-descriptionForeground opacity-50 hover:opacity-100" ,
1030+ ) }
1031+ onClick = { ( e ) => {
1032+ e . stopPropagation ( )
1033+ togglePinnedApiConfig ( option . value )
1034+ vscode . postMessage ( {
1035+ type : "toggleApiConfigPin" ,
1036+ text : option . value ,
1037+ } )
1038+ } }
1039+ title = { option . pinned ? t ( "chat:unpin" ) : t ( "chat:pin" ) } >
1040+ < Pin className = "size-3" />
1041+ </ div >
1042+ { option . value === currentApiConfigName && (
1043+ < Check className = "size-4 p-0.5 ml-1" />
1044+ ) }
1045+ </ div >
1046+ )
1047+ } }
9811048 />
9821049 </ div >
9831050 </ div >
0 commit comments