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.
This commit is contained in:
Piotr Osiewicz 2024-03-30 00:19:02 +01:00 committed by GitHub
parent 79b3b0c8ff
commit ed5bfcdddc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 1 deletions

1
Cargo.lock generated
View file

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

View file

@ -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

View file

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

View file

@ -591,6 +591,9 @@ impl TerminalPanel {
Some(())
}
pub fn pane(&self) -> &View<Pane> {
&self.pane
}
}
async fn wait_for_terminals_tasks(