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 5da1c0c48a96d23b282a1081c0f05a8d1d29308c..27fc366f1792ded67449a41330ddb6331a4b3f4b 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 83d6e20e61dd8e1ed61f812a585c77fd8fd3820d..b67c4a3bf114a90ab400fc234e10e8f7fc393ecd 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 0e444171c0cdaba1d1a7d80fc230a439ec3d92f9..d7738ff4a6e900449dd2941f20f6161d7e54d351 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 ef7c973b75bdc8a1310ff26fff66c0d1d833f8ab..89a188207115f472fcce20eebe3d54029677b052 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(