Open exactly one terminal on workspace::NewTerminal action (#10721)

Fixes https://github.com/zed-industries/zed/issues/4567

Release Notes:

- Fixed multiple terminals being opened on `workspace::NewTerminal`
calls ([4567](https://github.com/zed-industries/zed/issues/4567))
This commit is contained in:
Kirill Bulatov 2024-04-18 12:44:40 +03:00 committed by GitHub
parent bb97432e9a
commit d5c5394693
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -433,9 +433,18 @@ impl TerminalPanel {
_: &workspace::NewTerminal,
cx: &mut ViewContext<Workspace>,
) {
let has_no_terminals = workspace
.panel::<Self>(cx)
.map(|terminal_panel| terminal_panel.update(cx, |panel, cx| panel.has_no_terminals(cx)))
.unwrap_or(true);
let Some(this) = workspace.focus_panel::<Self>(cx) else {
return;
};
if has_no_terminals {
// `set_active` on focus, will already add a new terminal
// into an empty terminal pane, no need to add another one
return;
}
this.update(cx, |this, cx| this.add_terminal(None, None, cx))
}
@ -598,9 +607,14 @@ impl TerminalPanel {
Some(())
}
pub fn pane(&self) -> &View<Pane> {
&self.pane
}
fn has_no_terminals(&mut self, cx: &mut ViewContext<'_, Self>) -> bool {
self.pane.read(cx).items_len() == 0 && self.pending_terminals_to_add == 0
}
}
async fn wait_for_terminals_tasks(
@ -713,7 +727,7 @@ impl Panel for TerminalPanel {
}
fn set_active(&mut self, active: bool, cx: &mut ViewContext<Self>) {
if active && self.pane.read(cx).items_len() == 0 && self.pending_terminals_to_add == 0 {
if active && self.has_no_terminals(cx) {
self.add_terminal(None, None, cx)
}
}