Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions webview-ui/src/components/settings/ModelPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ModelPicker = ({

const { id: selectedModelId, info: selectedModelInfo } = useSelectedModel(apiConfiguration)

const [searchValue, setSearchValue] = useState(selectedModelId || "")
const [searchValue, setSearchValue] = useState("")

const onSelect = useCallback(
(modelId: string) => {
Expand All @@ -87,28 +87,25 @@ export const ModelPicker = ({
}

// Delay to ensure the popover is closed before setting the search value.
selectTimeoutRef.current = setTimeout(() => setSearchValue(modelId), 100)
selectTimeoutRef.current = setTimeout(() => setSearchValue(""), 100)
},
[modelIdKey, setApiConfigurationField],
)

const onOpenChange = useCallback(
(open: boolean) => {
setOpen(open)
const onOpenChange = useCallback((open: boolean) => {
setOpen(open)

// Abandon the current search if the popover is closed.
if (!open) {
// Clear any existing timeout
if (closeTimeoutRef.current) {
clearTimeout(closeTimeoutRef.current)
}

// Delay to ensure the popover is closed before setting the search value.
closeTimeoutRef.current = setTimeout(() => setSearchValue(selectedModelId), 100)
// Abandon the current search if the popover is closed.
if (!open) {
// Clear any existing timeout
if (closeTimeoutRef.current) {
clearTimeout(closeTimeoutRef.current)
}
},
[selectedModelId],
)

// Clear the search value when closing instead of prefilling it
closeTimeoutRef.current = setTimeout(() => setSearchValue(""), 100)
}
}, [])

const onClearSearch = useCallback(() => {
setSearchValue("")
Expand Down