diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index dd83b91ed0..fdd5a4fcbb 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -324,6 +324,20 @@ "side": "Left", "item_index": 0 } + ], + "cmd-9": [ + "workspace::ToggleSidebarItemFocus", + { + "side": "Right", + "item_index": 0 + } + ], + "cmd-shift-(": [ + "workspace::ToggleSidebarItem", + { + "side": "Right", + "item_index": 0 + } ] } }, diff --git a/crates/contacts_panel/src/contacts_panel.rs b/crates/contacts_panel/src/contacts_panel.rs index ba2ca12546..6af6da6f23 100644 --- a/crates/contacts_panel/src/contacts_panel.rs +++ b/crates/contacts_panel/src/contacts_panel.rs @@ -764,6 +764,10 @@ impl SidebarItem for ContactsPanel { .incoming_contact_requests() .is_empty() } + + fn contains_focused_view(&self, cx: &AppContext) -> bool { + self.filter_editor.is_focused(cx) + } } fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Element { diff --git a/crates/workspace/src/sidebar.rs b/crates/workspace/src/sidebar.rs index 366c74e43f..685782a2d2 100644 --- a/crates/workspace/src/sidebar.rs +++ b/crates/workspace/src/sidebar.rs @@ -10,10 +10,14 @@ use theme::Theme; pub trait SidebarItem: View { fn should_show_badge(&self, cx: &AppContext) -> bool; + fn contains_focused_view(&self, _: &AppContext) -> bool { + false + } } pub trait SidebarItemHandle { fn should_show_badge(&self, cx: &AppContext) -> bool; + fn is_focused(&self, cx: &AppContext) -> bool; fn to_any(&self) -> AnyViewHandle; } @@ -25,6 +29,10 @@ where self.read(cx).should_show_badge(cx) } + fn is_focused(&self, cx: &AppContext) -> bool { + ViewHandle::is_focused(&self, cx) || self.read(cx).contains_focused_view(cx) + } + fn to_any(&self) -> AnyViewHandle { self.into() } @@ -114,10 +122,10 @@ impl Sidebar { cx.notify(); } - pub fn active_item(&self) -> Option<&dyn SidebarItemHandle> { + pub fn active_item(&self) -> Option<&Rc> { self.active_item_ix .and_then(|ix| self.items.get(ix)) - .map(|item| item.view.as_ref()) + .map(|item| &item.view) } fn render_resize_handle(&self, theme: &Theme, cx: &mut RenderContext) -> ElementBox { @@ -170,7 +178,7 @@ impl View for Sidebar { container.add_child( Hook::new( - ChildView::new(active_item) + ChildView::new(active_item.to_any()) .constrained() .with_max_width(*self.custom_width.borrow()) .boxed(), diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 21d5581640..fada690bb5 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1123,13 +1123,13 @@ impl Workspace { }; let active_item = sidebar.update(cx, |sidebar, cx| { sidebar.activate_item(action.item_index, cx); - sidebar.active_item().map(|item| item.to_any()) + sidebar.active_item().cloned() }); if let Some(active_item) = active_item { if active_item.is_focused(cx) { cx.focus_self(); } else { - cx.focus(active_item); + cx.focus(active_item.to_any()); } } cx.notify();