Focus toggled elements when interacting with the sidebars

Also, restore focus on the workspace when there is no active item
on the sidebar that was just toggled.
This commit is contained in:
Antonio Scandurra 2021-08-27 10:01:44 +02:00
parent 1489c865e7
commit 386631debf
4 changed files with 16 additions and 1 deletions

View File

@ -2857,6 +2857,12 @@ impl Clone for AnyViewHandle {
}
}
impl From<&AnyViewHandle> for AnyViewHandle {
fn from(handle: &AnyViewHandle) -> Self {
handle.clone()
}
}
impl<T: View> From<&ViewHandle<T>> for AnyViewHandle {
fn from(handle: &ViewHandle<T>) -> Self {
handle

View File

@ -214,6 +214,10 @@ impl View for ChatPanel {
.with_style(&theme.chat_panel.container)
.boxed()
}
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
cx.focus(&self.input_editor);
}
}
fn format_timestamp(mut timestamp: OffsetDateTime, mut now: OffsetDateTime) -> String {

View File

@ -767,6 +767,11 @@ impl Workspace {
Side::Right => &mut self.right_sidebar,
};
sidebar.toggle_item(action.0.item_index);
if let Some(active_item) = sidebar.active_item() {
cx.focus(active_item);
} else {
cx.focus_self();
}
cx.notify();
}

View File

@ -49,7 +49,7 @@ impl Sidebar {
if self.active_item_ix == Some(item_ix) {
self.active_item_ix = None;
} else {
self.active_item_ix = Some(item_ix)
self.active_item_ix = Some(item_ix);
}
}