diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index cf07def52a..4e4a7e92aa 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -139,7 +139,12 @@ impl Picker { max_size: vec2f(540., 420.), confirmed: false, }; - cx.defer(|this, cx| this.update_matches(String::new(), cx)); + cx.defer(|this, cx| { + if let Some(delegate) = this.delegate.upgrade(cx) { + cx.observe(&delegate, |_, _, cx| cx.notify()).detach(); + this.update_matches(String::new(), cx) + } + }); this } @@ -174,7 +179,6 @@ impl Picker { pub fn update_matches(&mut self, query: String, cx: &mut ViewContext) { if let Some(delegate) = self.delegate.upgrade(cx) { let update = delegate.update(cx, |d, cx| d.update_matches(query, cx)); - cx.notify(); cx.spawn(|this, mut cx| async move { update.await; this.update(&mut cx, |this, cx| { diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs index cbdc83d19e..d2c6850e8b 100644 --- a/crates/project_symbols/src/project_symbols.rs +++ b/crates/project_symbols/src/project_symbols.rs @@ -28,6 +28,7 @@ pub struct ProjectSymbolsView { symbols: Vec, match_candidates: Vec, show_worktree_root_name: bool, + pending_update: Task<()>, matches: Vec, } @@ -65,6 +66,7 @@ impl ProjectSymbolsView { match_candidates: Default::default(), matches: Default::default(), show_worktree_root_name: false, + pending_update: Task::ready(()), } } @@ -193,7 +195,7 @@ impl PickerDelegate for ProjectSymbolsView { let symbols = self .project .update(cx, |project, cx| project.symbols(&query, cx)); - cx.spawn_weak(|this, mut cx| async move { + self.pending_update = cx.spawn_weak(|this, mut cx| async move { let symbols = symbols.await.log_err(); if let Some(this) = this.upgrade(&cx) { if let Some(symbols) = symbols { @@ -214,7 +216,8 @@ impl PickerDelegate for ProjectSymbolsView { }); } } - }) + }); + Task::ready(()) } fn render_match(&self, ix: usize, selected: bool, cx: &AppContext) -> ElementBox {