tab_switcher: Add support for tab switcher in terminal panel (#9963)

Piotr Osiewicz created

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.

Change summary

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(-)

Detailed changes

Cargo.lock 🔗

@@ -9603,6 +9603,7 @@ dependencies = [
  "project",
  "serde",
  "serde_json",
+ "terminal_view",
  "theme",
  "ui",
  "util",

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

crates/tab_switcher/src/tab_switcher.rs 🔗

@@ -56,7 +56,16 @@ impl TabSwitcher {
     }
 
     fn open(action: &Toggle, workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
-        let weak_pane = workspace.active_pane().downgrade();
+        let terminal = workspace.panel::<terminal_view::terminal_panel::TerminalPanel>(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)