From 386631debf2319e3dd56f9783298923d0cb724c6 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 27 Aug 2021 10:01:44 +0200 Subject: [PATCH] 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. --- gpui/src/app.rs | 6 ++++++ zed/src/chat_panel.rs | 4 ++++ zed/src/workspace.rs | 5 +++++ zed/src/workspace/sidebar.rs | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 1e531d3692ea41af3444e55e91d41c873cde568b..a37e6e415723e83f1872c1755b74e8a64638650d 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -2857,6 +2857,12 @@ impl Clone for AnyViewHandle { } } +impl From<&AnyViewHandle> for AnyViewHandle { + fn from(handle: &AnyViewHandle) -> Self { + handle.clone() + } +} + impl From<&ViewHandle> for AnyViewHandle { fn from(handle: &ViewHandle) -> Self { handle diff --git a/zed/src/chat_panel.rs b/zed/src/chat_panel.rs index 03630ac6c8808857a82bbb54391f6e70f1f21d7d..140ddcf28d09e4220d4e48e7233e4530d2871f5d 100644 --- a/zed/src/chat_panel.rs +++ b/zed/src/chat_panel.rs @@ -214,6 +214,10 @@ impl View for ChatPanel { .with_style(&theme.chat_panel.container) .boxed() } + + fn on_focus(&mut self, cx: &mut ViewContext) { + cx.focus(&self.input_editor); + } } fn format_timestamp(mut timestamp: OffsetDateTime, mut now: OffsetDateTime) -> String { diff --git a/zed/src/workspace.rs b/zed/src/workspace.rs index e5785028a36e431cea19c91953e99a10d76c5437..2d7f44fd011c56721af7d50cd418bc0a9ebc6165 100644 --- a/zed/src/workspace.rs +++ b/zed/src/workspace.rs @@ -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(); } diff --git a/zed/src/workspace/sidebar.rs b/zed/src/workspace/sidebar.rs index 242b557c39841687930413a3ab013b819e771403..f0bafd5472a71b796da24867f64b53b5bd04339b 100644 --- a/zed/src/workspace/sidebar.rs +++ b/zed/src/workspace/sidebar.rs @@ -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); } }