From d57bc9b3dcd2b58ee909e54b8216772d70d7d0e4 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 19 Jun 2021 11:06:14 -0700 Subject: [PATCH] CloseCurrentPane on last pane in a tab results in window closing The issue is that the pane was only removed from the tab when explicitly closed, leaving it to be later detected and flushed. However, in the meantime, when performing eg: cursor blink maintenance, if the set of panes in the tab is empty then the window would close. The resolution is to ask the mux (rather than the tab) to kill the pane, so that the cascading closure of the tab causes the window's active tab to reference the correct remaining tab. refs: #890 --- docs/changelog.md | 1 + mux/src/lib.rs | 6 ++++++ mux/src/window.rs | 9 +++------ wezterm-gui/src/termwindow/mod.rs | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 71e676780..f224e289d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -42,6 +42,7 @@ As features stabilize some brief notes about them will accumulate here. * Improved: we now draw sextant glyphs from the Unicode Symbols for Legacy Computing block (1FB00) when `custom_block_glyphs` is enabled. * Changed: `COLORTERM=truecolor` is now set in the environment. [#875](https://github.com/wez/wezterm/issues/875) * New: `wezterm cli spawn --new-window` flag for creating a new window via the CLI [#887](https://github.com/wez/wezterm/issues/887) +* Fixed: closing last pane in a tab via `CloseCurrentPane` could cause the window to close [#890](https://github.com/wez/wezterm/issues/890) ### 20210502-154244-3f7122cb diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 78c5dbe93..e3a7067e3 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -396,6 +396,12 @@ impl Mux { let tab = self.tabs.borrow_mut().remove(&tab_id)?; + if let Ok(mut windows) = self.windows.try_borrow_mut() { + for w in windows.values_mut() { + w.remove_by_id(tab_id); + } + } + let mut pane_ids = vec![]; for pos in tab.iter_panes() { pane_ids.push(pos.pane.pane_id()); diff --git a/mux/src/window.rs b/mux/src/window.rs index 22ed16383..06f444d1d 100644 --- a/mux/src/window.rs +++ b/mux/src/window.rs @@ -120,15 +120,12 @@ impl Window { tab } - pub fn remove_by_id(&mut self, id: TabId) -> bool { + pub fn remove_by_id(&mut self, id: TabId) { + let active = self.get_active().map(Rc::clone); if let Some(idx) = self.idx_by_id(id) { - let active = self.get_active().map(Rc::clone); self.tabs.remove(idx); - self.fixup_active_tab_after_removal(active); - true - } else { - false } + self.fixup_active_tab_after_removal(active); } pub fn get_active(&self) -> Option<&Rc> { diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index dd255eabf..a62d64f1a 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -1058,6 +1058,7 @@ impl TermWindow { let panes = self.get_panes_to_render(); if panes.is_empty() { + log::warn!("maintain_blink: get_panes_to_render.is_empty() -> close window"); self.window.as_ref().unwrap().close(); return (false, None); } @@ -1915,7 +1916,7 @@ impl TermWindow { self.assign_overlay_for_pane(pane_id, overlay); promise::spawn::spawn(future).detach(); } else { - tab.kill_pane(pane_id); + mux.remove_pane(pane_id); } }