Preserve contacts popover editor contents when switching to search mode
This commit is contained in:
parent
e7af3f223a
commit
01e3173ed0
4 changed files with 41 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
use client::{ContactRequestStatus, User, UserStore};
|
use client::{ContactRequestStatus, User, UserStore};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
elements::*, AnyViewHandle, Entity, ModelHandle, MouseState, MutableAppContext, RenderContext,
|
elements::*, AnyViewHandle, AppContext, Entity, ModelHandle, MouseState, MutableAppContext,
|
||||||
Task, View, ViewContext, ViewHandle,
|
RenderContext, Task, View, ViewContext, ViewHandle,
|
||||||
};
|
};
|
||||||
use picker::{Picker, PickerDelegate};
|
use picker::{Picker, PickerDelegate};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
@ -178,4 +178,14 @@ impl ContactFinder {
|
||||||
selected_index: 0,
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,6 +294,16 @@ impl ContactList {
|
||||||
this
|
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>) {
|
fn remove_contact(&mut self, request: &RemoveContact, cx: &mut ViewContext<Self>) {
|
||||||
let user_id = request.0;
|
let user_id = request.0;
|
||||||
let user_store = self.user_store.clone();
|
let user_store = self.user_store.clone();
|
||||||
|
|
|
@ -43,19 +43,23 @@ impl ContactsPopover {
|
||||||
user_store,
|
user_store,
|
||||||
_subscription: None,
|
_subscription: None,
|
||||||
};
|
};
|
||||||
this.show_contact_list(cx);
|
this.show_contact_list(String::new(), cx);
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_contact_finder(&mut self, _: &ToggleContactFinder, cx: &mut ViewContext<Self>) {
|
fn toggle_contact_finder(&mut self, _: &ToggleContactFinder, cx: &mut ViewContext<Self>) {
|
||||||
match &self.child {
|
match &self.child {
|
||||||
Child::ContactList(_) => self.show_contact_finder(cx),
|
Child::ContactList(list) => self.show_contact_finder(list.read(cx).editor_text(cx), cx),
|
||||||
Child::ContactFinder(_) => self.show_contact_list(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>) {
|
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));
|
let child = cx.add_view(|cx| {
|
||||||
|
ContactFinder::new(self.user_store.clone(), cx).with_editor_text(editor_text, cx)
|
||||||
|
});
|
||||||
cx.focus(&child);
|
cx.focus(&child);
|
||||||
self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event {
|
self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event {
|
||||||
crate::contact_finder::Event::Dismissed => cx.emit(Event::Dismissed),
|
crate::contact_finder::Event::Dismissed => cx.emit(Event::Dismissed),
|
||||||
|
@ -64,9 +68,11 @@ impl ContactsPopover {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_contact_list(&mut self, cx: &mut ViewContext<ContactsPopover>) {
|
fn show_contact_list(&mut self, editor_text: String, cx: &mut ViewContext<ContactsPopover>) {
|
||||||
let child =
|
let child = cx.add_view(|cx| {
|
||||||
cx.add_view(|cx| ContactList::new(self.project.clone(), self.user_store.clone(), cx));
|
ContactList::new(self.project.clone(), self.user_store.clone(), cx)
|
||||||
|
.with_editor_text(editor_text, cx)
|
||||||
|
});
|
||||||
cx.focus(&child);
|
cx.focus(&child);
|
||||||
self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event {
|
self._subscription = Some(cx.subscribe(&child, |_, _, event, cx| match event {
|
||||||
crate::contact_list::Event::Dismissed => cx.emit(Event::Dismissed),
|
crate::contact_list::Event::Dismissed => cx.emit(Event::Dismissed),
|
||||||
|
|
|
@ -205,6 +205,11 @@ impl<D: PickerDelegate> Picker<D> {
|
||||||
self.query_editor.read(cx).text(cx)
|
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(
|
fn on_query_editor_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: ViewHandle<Editor>,
|
_: ViewHandle<Editor>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue