From ed5bfcdddcdc2e9e0e3b1245b060d2f5b892104c Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Sat, 30 Mar 2024 00:19:02 +0100 Subject: [PATCH] tab_switcher: Add support for tab switcher in terminal panel (#9963) tab switcher retrieves active pane from workspace, but that function is not aware of Terminal Panel's pane. Thus in this PR we retrieve it manually and use it as the active pane if terminal panel has focus. Release Notes: - Fixed tab switcher not working in terminal panel. --- Cargo.lock | 1 + crates/tab_switcher/Cargo.toml | 1 + crates/tab_switcher/src/tab_switcher.rs | 11 ++++++++++- crates/terminal_view/src/terminal_panel.rs | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 5da1c0c48a..27fc366f17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9603,6 +9603,7 @@ dependencies = [ "project", "serde", "serde_json", + "terminal_view", "theme", "ui", "util", diff --git a/crates/tab_switcher/Cargo.toml b/crates/tab_switcher/Cargo.toml index 83d6e20e61..b67c4a3bf1 100644 --- a/crates/tab_switcher/Cargo.toml +++ b/crates/tab_switcher/Cargo.toml @@ -15,6 +15,7 @@ gpui.workspace = true menu.workspace = true picker.workspace = true serde.workspace = true +terminal_view.workspace = true ui.workspace = true util.workspace = true workspace.workspace = true diff --git a/crates/tab_switcher/src/tab_switcher.rs b/crates/tab_switcher/src/tab_switcher.rs index 0e444171c0..d7738ff4a6 100644 --- a/crates/tab_switcher/src/tab_switcher.rs +++ b/crates/tab_switcher/src/tab_switcher.rs @@ -56,7 +56,16 @@ impl TabSwitcher { } fn open(action: &Toggle, workspace: &mut Workspace, cx: &mut ViewContext) { - let weak_pane = workspace.active_pane().downgrade(); + let terminal = workspace.panel::(cx); + let terminal_pane = terminal.and_then(|terminal| { + terminal + .focus_handle(cx) + .contains_focused(cx) + .then(|| terminal.read(cx).pane()) + }); + let weak_pane = terminal_pane + .unwrap_or_else(|| workspace.active_pane()) + .downgrade(); workspace.toggle_modal(cx, |cx| { let delegate = TabSwitcherDelegate::new(action, cx.view().downgrade(), weak_pane, cx); TabSwitcher::new(delegate, cx) diff --git a/crates/terminal_view/src/terminal_panel.rs b/crates/terminal_view/src/terminal_panel.rs index ef7c973b75..89a1882071 100644 --- a/crates/terminal_view/src/terminal_panel.rs +++ b/crates/terminal_view/src/terminal_panel.rs @@ -591,6 +591,9 @@ impl TerminalPanel { Some(()) } + pub fn pane(&self) -> &View { + &self.pane + } } async fn wait_for_terminals_tasks(