From a103b6d97adcc439e27cec0d3bb2c0f72a79095d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 28 Aug 2023 07:28:23 -0700 Subject: [PATCH] fix CloseCurrentPane leaving a stranded pane in a tab Repro for this issue was: ```console $ WEZTERM_LOG=mux=trace,info ./target/debug/wezterm -n --config 'exit_behavior="CloseOnCleanExit"' ``` Then: * Split left/right * CloseCurrentPane refs: #4030 --- docs/changelog.md | 1 + mux/src/tab.rs | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4342de1ba..ead59931c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -92,6 +92,7 @@ As features stabilize some brief notes about them will accumulate here. * Text cursor filled the scaled-by `line_height` and `cell_width` dimensions rather than the native font dimensions and looked weird when either config option was not set to `1.0`. #2882 +* Using `CloseCurrentPane` could sometimes leave a stranded pane in a tab. #4030 #### Updated * Bundled harfbuzz to 8.1.1 diff --git a/mux/src/tab.rs b/mux/src/tab.rs index ee891de12..773557e11 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -1554,8 +1554,26 @@ impl TabInner { } fn prune_dead_panes(&mut self) -> bool { + let mux = Mux::get(); !self - .remove_pane_if(|_, pane| pane.is_dead(), true) + .remove_pane_if( + |_, pane| { + // If the pane is no longer known to the mux, then its liveness + // state isn't guaranteed to be monitored or updated, so let's + // consider the pane effectively dead if it isn't in the mux. + // + let in_mux = mux.get_pane(pane.pane_id()).is_some(); + let dead = pane.is_dead(); + log::trace!( + "prune_dead_panes: pane_id={} dead={} in_mux={}", + pane.pane_id(), + dead, + in_mux + ); + dead || !in_mux + }, + true, + ) .is_empty() }