diff --git a/crates/story/src/picker_story.rs b/crates/story/src/picker_story.rs index 11dfb041..55d74a1a 100644 --- a/crates/story/src/picker_story.rs +++ b/crates/story/src/picker_story.rs @@ -37,7 +37,7 @@ impl ListDelegate for ListItemDeletegate { let query = query.to_string(); cx.spawn(move |this, mut cx| async move { // Simulate a slow search. - let sleep = (0.15..0.3).fake(); + let sleep = (0.05..0.1).fake(); Timer::after(Duration::from_secs_f64(sleep)).await; this.update(&mut cx, |this, cx| { diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 69b54f51..5b9b1263 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -79,6 +79,7 @@ pub struct List { scrollbar_state: Rc>, selected_index: Option, + _search_task: Task<()>, } impl List @@ -108,6 +109,7 @@ where max_height: None, enable_scrollbar: true, loading: false, + _search_task: Task::Ready(None), } } @@ -195,16 +197,15 @@ where self.set_loading(true, cx); let search = self.delegate.perform_search(&text, cx); - cx.spawn(|this, mut cx| async move { + self._search_task = cx.spawn(|this, mut cx| async move { search.await; // Always wait 100ms to avoid flicker Timer::after(Duration::from_millis(100)).await; - this.update(&mut cx, |this, cx| { + let _ = this.update(&mut cx, |this, cx| { this.last_query = Some(text); this.set_loading(false, cx); - }) - }) - .detach(); + }); + }); } InputEvent::PressEnter => self.action_confirm(&Confirm, cx), _ => {}