list: Select first item on search. (#798)

This commit is contained in:
Jason Lee 2025-04-17 17:29:02 +08:00 committed by GitHub
parent 5b508d7219
commit 034e465d28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -170,7 +170,6 @@ impl ListDelegate for CompanyListDelegate {
.filter(|company| company.name.to_lowercase().contains(&query.to_lowercase()))
.cloned()
.collect();
Task::ready(())
}
@ -277,7 +276,7 @@ impl ListStory {
let delegate = CompanyListDelegate {
matched_companies: companies.clone(),
companies,
selected_index: None,
selected_index: Some(0),
confirmed_index: None,
query: "".to_string(),
loading: false,

View file

@ -339,6 +339,12 @@ where
self.set_querying(true, window, cx);
let search = self.delegate.perform_search(&text, window, cx);
if self.delegate.items_count(cx) > 0 {
self.set_selected_index(Some(0), window, cx);
} else {
self.set_selected_index(None, window, cx);
}
self._search_task = cx.spawn_in(window, async move |this, window| {
search.await;