Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Preserve contacts popover editor contents when switching to search mode
Julia01e3173ed0ca
diff --git a/crates/collab_ui/src/contact_finder.rs b/crates/collab_ui/src/contact_finder.rsindex 98f70e83f0e..ff783c62748 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 {+ 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.rsindex 3bb036d3366..dd6683292e3 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 {+ self.filter_editor+ .update(cx, |picker, cx| picker.set_text(editor_text, cx));+ self+ }+fn remove_contact(&mut self, request: &RemoveContact, cx: &mut ViewContext<Self>) {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.rsindex 0c67ef4c7c0..017950e6cc7 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<Self>) {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<ContactsPopover>) {- 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<ContactsPopover>) {+ 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<ContactsPopover>) {- 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<ContactsPopover>) {+ 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.rsindex e4d062d575a..547e0160360 100644--- a/crates/picker/src/picker.rs+++ b/crates/picker/src/picker.rs@@ -205,6 +205,11 @@ impl<D: PickerDelegate> Picker<D> {self.query_editor.read(cx).text(cx)}+ pub fn set_query(&self, query: impl Into<Arc<str>>, cx: &mut ViewContext<Self>) {+ self.query_editor+ .update(cx, |editor, cx| editor.set_text(query, cx));+ }+fn on_query_editor_event(&mut self,_: ViewHandle<Editor>,