diff --git a/crates/collab_ui/src/contact_finder.rs b/crates/collab_ui/src/contact_finder.rs index 98f70e83f0..ff783c6274 100644 --- a/crates/collab_ui/src/contact_finder.rs +++ b/crates/collab_ui/src/contact_finder.rs @@ -1,7 +1,7 @@ use client::{ContactRequestStatus, User, UserStore}; use gpui::{ - elements::*, AnyViewHandle, Entity, ModelHandle, MouseState, MutableAppContext, RenderContext, - Task, View, ViewContext, ViewHandle, + elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, MouseState, MutableAppContext, + RenderContext, Task, View, ViewContext, ViewHandle, }; use picker::{Picker, PickerDelegate}; use settings::Settings; @@ -178,4 +178,14 @@ impl ContactFinder { selected_index: 0, } } + + pub fn editor_text(&self, cx: &AppContext) -> String { + self.picker.read(cx).query(cx) + } + + pub fn with_editor_text(self, editor_text: String, cx: &mut ViewContext) -> Self { + self.picker + .update(cx, |picker, cx| picker.set_query(editor_text, cx)); + self + } } diff --git a/crates/collab_ui/src/contact_list.rs b/crates/collab_ui/src/contact_list.rs index 3bb036d336..dd6683292e 100644 --- a/crates/collab_ui/src/contact_list.rs +++ b/crates/collab_ui/src/contact_list.rs @@ -294,6 +294,16 @@ impl ContactList { this } + pub fn editor_text(&self, cx: &AppContext) -> String { + self.filter_editor.read(cx).text(cx) + } + + pub fn with_editor_text(self, editor_text: String, cx: &mut ViewContext) -> Self { + self.filter_editor + .update(cx, |picker, cx| picker.set_text(editor_text, cx)); + self + } + fn remove_contact(&mut self, request: &RemoveContact, cx: &mut ViewContext) { let user_id = request.0; let user_store = self.user_store.clone(); diff --git a/crates/collab_ui/src/contacts_popover.rs b/crates/collab_ui/src/contacts_popover.rs index 0c67ef4c7c..017950e6cc 100644 --- a/crates/collab_ui/src/contacts_popover.rs +++ b/crates/collab_ui/src/contacts_popover.rs @@ -43,19 +43,23 @@ impl ContactsPopover { user_store, _subscription: None, }; - this.show_contact_list(cx); + this.show_contact_list(String::new(), cx); this } fn toggle_contact_finder(&mut self, _: &ToggleContactFinder, cx: &mut ViewContext) { match &self.child { - Child::ContactList(_) => self.show_contact_finder(cx), - Child::ContactFinder(_) => self.show_contact_list(cx), + Child::ContactList(list) => self.show_contact_finder(list.read(cx).editor_text(cx), cx), + Child::ContactFinder(finder) => { + self.show_contact_list(finder.read(cx).editor_text(cx), cx) + } } } - fn show_contact_finder(&mut self, cx: &mut ViewContext) { - let child = cx.add_view(|cx| ContactFinder::new(self.user_store.clone(), cx)); + fn show_contact_finder(&mut self, editor_text: String, cx: &mut ViewContext) { + let child = cx.add_view(|cx| { + ContactFinder::new(self.user_store.clone(), cx).with_editor_text(editor_text, cx) + }); cx.focus(&child); self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event { crate::contact_finder::Event::Dismissed => cx.emit(Event::Dismissed), @@ -64,9 +68,11 @@ impl ContactsPopover { cx.notify(); } - fn show_contact_list(&mut self, cx: &mut ViewContext) { - let child = - cx.add_view(|cx| ContactList::new(self.project.clone(), self.user_store.clone(), cx)); + fn show_contact_list(&mut self, editor_text: String, cx: &mut ViewContext) { + let child = cx.add_view(|cx| { + ContactList::new(self.project.clone(), self.user_store.clone(), cx) + .with_editor_text(editor_text, cx) + }); cx.focus(&child); self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event { crate::contact_list::Event::Dismissed => cx.emit(Event::Dismissed), diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index e4d062d575..547e016036 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -205,6 +205,11 @@ impl Picker { self.query_editor.read(cx).text(cx) } + pub fn set_query(&self, query: impl Into>, cx: &mut ViewContext) { + self.query_editor + .update(cx, |editor, cx| editor.set_text(query, cx)); + } + fn on_query_editor_event( &mut self, _: ViewHandle,