Merge pull request #857 from zed-industries/file-finder-fixes

File finder fixes
This commit is contained in:
Max Brunsfeld 2022-04-19 13:40:40 -07:00 committed by GitHub
commit c2fa7b9bf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View file

@ -129,7 +129,7 @@ impl FileFinder {
} }
fn project_updated(&mut self, _: ModelHandle<Project>, cx: &mut ViewContext<Self>) { fn project_updated(&mut self, _: ModelHandle<Project>, cx: &mut ViewContext<Self>) {
self.spawn_search(self.latest_search_query.clone(), cx) self.spawn_search(self.picker.read(cx).query(cx), cx)
.detach(); .detach();
} }
@ -379,7 +379,7 @@ mod tests {
// Simulate a search being cancelled after the time limit, // Simulate a search being cancelled after the time limit,
// returning only a subset of the matches that would have been found. // returning only a subset of the matches that would have been found.
finder.spawn_search(query.clone(), cx).detach(); drop(finder.spawn_search(query.clone(), cx));
finder.set_matches( finder.set_matches(
finder.latest_search_id, finder.latest_search_id,
true, // did-cancel true, // did-cancel
@ -389,7 +389,7 @@ mod tests {
); );
// Simulate another cancellation. // Simulate another cancellation.
finder.spawn_search(query.clone(), cx).detach(); drop(finder.spawn_search(query.clone(), cx));
finder.set_matches( finder.set_matches(
finder.latest_search_id, finder.latest_search_id,
true, // did-cancel true, // did-cancel

View file

@ -18,7 +18,6 @@ pub struct Picker<D: PickerDelegate> {
delegate: WeakViewHandle<D>, delegate: WeakViewHandle<D>,
query_editor: ViewHandle<Editor>, query_editor: ViewHandle<Editor>,
list_state: UniformListState, list_state: UniformListState,
update_task: Option<Task<()>>,
max_size: Vector2F, max_size: Vector2F,
confirmed: bool, confirmed: bool,
} }
@ -136,7 +135,6 @@ impl<D: PickerDelegate> Picker<D> {
let this = Self { let this = Self {
query_editor, query_editor,
list_state: Default::default(), list_state: Default::default(),
update_task: None,
delegate, delegate,
max_size: vec2f(500., 420.), max_size: vec2f(500., 420.),
confirmed: false, confirmed: false,
@ -150,6 +148,10 @@ impl<D: PickerDelegate> Picker<D> {
self self
} }
pub fn query(&self, cx: &AppContext) -> String {
self.query_editor.read(cx).text(cx)
}
fn on_query_editor_event( fn on_query_editor_event(
&mut self, &mut self,
_: ViewHandle<Editor>, _: ViewHandle<Editor>,
@ -171,10 +173,10 @@ impl<D: PickerDelegate> Picker<D> {
fn update_matches(&mut self, cx: &mut ViewContext<Self>) { fn update_matches(&mut self, cx: &mut ViewContext<Self>) {
if let Some(delegate) = self.delegate.upgrade(cx) { if let Some(delegate) = self.delegate.upgrade(cx) {
let query = self.query_editor.read(cx).text(cx); let query = self.query(cx);
let update = delegate.update(cx, |d, cx| d.update_matches(query, cx)); let update = delegate.update(cx, |d, cx| d.update_matches(query, cx));
cx.notify(); cx.notify();
self.update_task = Some(cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
update.await; update.await;
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
if let Some(delegate) = this.delegate.upgrade(cx) { if let Some(delegate) = this.delegate.upgrade(cx) {
@ -187,10 +189,10 @@ impl<D: PickerDelegate> Picker<D> {
}; };
this.list_state.scroll_to(target); this.list_state.scroll_to(target);
cx.notify(); cx.notify();
this.update_task.take();
} }
}); });
})); })
.detach()
} }
} }