Fix selections and enter-to-create-file
This commit is contained in:
parent
2605ae1ef5
commit
a5cb4c6d52
1 changed files with 43 additions and 18 deletions
|
@ -197,7 +197,7 @@ impl CollabPanel {
|
||||||
if !query.is_empty() {
|
if !query.is_empty() {
|
||||||
this.selection.take();
|
this.selection.take();
|
||||||
}
|
}
|
||||||
this.update_entries(cx);
|
this.update_entries(false, cx);
|
||||||
if !query.is_empty() {
|
if !query.is_empty() {
|
||||||
this.selection = this
|
this.selection = this
|
||||||
.entries
|
.entries
|
||||||
|
@ -220,7 +220,7 @@ impl CollabPanel {
|
||||||
cx.subscribe(&channel_name_editor, |this, _, event, cx| {
|
cx.subscribe(&channel_name_editor, |this, _, event, cx| {
|
||||||
if let editor::Event::Blurred = event {
|
if let editor::Event::Blurred = event {
|
||||||
this.take_editing_state(cx);
|
this.take_editing_state(cx);
|
||||||
this.update_entries(cx);
|
this.update_entries(false, cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -358,7 +358,7 @@ impl CollabPanel {
|
||||||
list_state,
|
list_state,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update_entries(cx);
|
this.update_entries(false, cx);
|
||||||
|
|
||||||
// Update the dock position when the setting changes.
|
// Update the dock position when the setting changes.
|
||||||
let mut old_dock_position = this.position(cx);
|
let mut old_dock_position = this.position(cx);
|
||||||
|
@ -376,13 +376,18 @@ impl CollabPanel {
|
||||||
|
|
||||||
let active_call = ActiveCall::global(cx);
|
let active_call = ActiveCall::global(cx);
|
||||||
this.subscriptions
|
this.subscriptions
|
||||||
.push(cx.observe(&this.user_store, |this, _, cx| this.update_entries(cx)));
|
.push(cx.observe(&this.user_store, |this, _, cx| {
|
||||||
|
this.update_entries(false, cx)
|
||||||
|
}));
|
||||||
this.subscriptions
|
this.subscriptions
|
||||||
.push(cx.observe(&this.channel_store, |this, _, cx| this.update_entries(cx)));
|
.push(cx.observe(&this.channel_store, |this, _, cx| {
|
||||||
|
this.update_entries(false, cx)
|
||||||
|
}));
|
||||||
this.subscriptions
|
this.subscriptions
|
||||||
.push(cx.observe(&active_call, |this, _, cx| this.update_entries(cx)));
|
.push(cx.observe(&active_call, |this, _, cx| this.update_entries(false, cx)));
|
||||||
this.subscriptions
|
this.subscriptions.push(
|
||||||
.push(cx.observe_global::<StaffMode, _>(move |this, cx| this.update_entries(cx)));
|
cx.observe_global::<StaffMode, _>(move |this, cx| this.update_entries(false, cx)),
|
||||||
|
);
|
||||||
|
|
||||||
this
|
this
|
||||||
})
|
})
|
||||||
|
@ -434,7 +439,7 @@ impl CollabPanel {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_entries(&mut self, cx: &mut ViewContext<Self>) {
|
fn update_entries(&mut self, select_editor: bool, cx: &mut ViewContext<Self>) {
|
||||||
let channel_store = self.channel_store.read(cx);
|
let channel_store = self.channel_store.read(cx);
|
||||||
let user_store = self.user_store.read(cx);
|
let user_store = self.user_store.read(cx);
|
||||||
let query = self.filter_editor.read(cx).text(cx);
|
let query = self.filter_editor.read(cx).text(cx);
|
||||||
|
@ -743,6 +748,14 @@ impl CollabPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if select_editor {
|
||||||
|
for (ix, entry) in self.entries.iter().enumerate() {
|
||||||
|
if matches!(*entry, ListEntry::ChannelEditor { .. }) {
|
||||||
|
self.selection = Some(ix);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if let Some(prev_selected_entry) = prev_selected_entry {
|
if let Some(prev_selected_entry) = prev_selected_entry {
|
||||||
self.selection.take();
|
self.selection.take();
|
||||||
for (ix, entry) in self.entries.iter().enumerate() {
|
for (ix, entry) in self.entries.iter().enumerate() {
|
||||||
|
@ -752,6 +765,7 @@ impl CollabPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let old_scroll_top = self.list_state.logical_scroll_top();
|
let old_scroll_top = self.list_state.logical_scroll_top();
|
||||||
self.list_state.reset(self.entries.len());
|
self.list_state.reset(self.entries.len());
|
||||||
|
@ -1643,7 +1657,7 @@ impl CollabPanel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_entries(cx);
|
self.update_entries(false, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
|
fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
|
||||||
|
@ -1724,17 +1738,28 @@ impl CollabPanel {
|
||||||
ListEntry::Channel(channel) => {
|
ListEntry::Channel(channel) => {
|
||||||
self.join_channel(channel.id, cx);
|
self.join_channel(channel.id, cx);
|
||||||
}
|
}
|
||||||
|
ListEntry::ChannelEditor { .. } => {
|
||||||
|
self.confirm_channel_edit(cx);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some((editing_state, channel_name)) = self.take_editing_state(cx) {
|
} else {
|
||||||
|
self.confirm_channel_edit(cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn confirm_channel_edit(&mut self, cx: &mut ViewContext<'_, '_, CollabPanel>) {
|
||||||
|
if let Some((editing_state, channel_name)) = self.take_editing_state(cx) {
|
||||||
let create_channel = self.channel_store.update(cx, |channel_store, _| {
|
let create_channel = self.channel_store.update(cx, |channel_store, _| {
|
||||||
channel_store.create_channel(&channel_name, editing_state.parent_id)
|
channel_store.create_channel(&channel_name, editing_state.parent_id)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.update_entries(false, cx);
|
||||||
|
|
||||||
cx.foreground()
|
cx.foreground()
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
create_channel.await.ok();
|
create_channel.await.log_err();
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
@ -1746,7 +1771,7 @@ impl CollabPanel {
|
||||||
} else {
|
} else {
|
||||||
self.collapsed_sections.push(section);
|
self.collapsed_sections.push(section);
|
||||||
}
|
}
|
||||||
self.update_entries(cx);
|
self.update_entries(false, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leave_call(cx: &mut ViewContext<Self>) {
|
fn leave_call(cx: &mut ViewContext<Self>) {
|
||||||
|
@ -1771,7 +1796,7 @@ impl CollabPanel {
|
||||||
|
|
||||||
fn new_root_channel(&mut self, cx: &mut ViewContext<Self>) {
|
fn new_root_channel(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
self.channel_editing_state = Some(ChannelEditingState { parent_id: None });
|
self.channel_editing_state = Some(ChannelEditingState { parent_id: None });
|
||||||
self.update_entries(cx);
|
self.update_entries(true, cx);
|
||||||
cx.focus(self.channel_name_editor.as_any());
|
cx.focus(self.channel_name_editor.as_any());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
@ -1780,7 +1805,7 @@ impl CollabPanel {
|
||||||
self.channel_editing_state = Some(ChannelEditingState {
|
self.channel_editing_state = Some(ChannelEditingState {
|
||||||
parent_id: Some(action.channel_id),
|
parent_id: Some(action.channel_id),
|
||||||
});
|
});
|
||||||
self.update_entries(cx);
|
self.update_entries(true, cx);
|
||||||
cx.focus(self.channel_name_editor.as_any());
|
cx.focus(self.channel_name_editor.as_any());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue