diff --git a/mux/src/domain.rs b/mux/src/domain.rs index 3cb3767d5c3..2eacee8ad1d 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -84,7 +84,7 @@ pub trait Domain: Downcast + Send + Sync { None => anyhow::bail!("Invalid tab id {}", tab), }; - let pane_index = match tab + let mut pane_index = match tab .iter_panes_ignoring_zoom() .iter() .find(|p| p.pane.pane_id() == pane_id) @@ -119,6 +119,18 @@ pub trait Domain: Downcast + Send + Sync { anyhow::anyhow!("pane {} not found in its containing tab!?", src_pane_id) })?; + // May need to update pane_index if src_pane was also in the same tab + if src_tab.tab_id() == tab.tab_id() { + pane_index = match tab + .iter_panes_ignoring_zoom() + .iter() + .find(|p| p.pane.pane_id() == pane_id) + { + Some(p) => p.index, + None => anyhow::bail!("invalid pane id {}", pane_id), + }; + } + if src_tab.is_dead() { mux.remove_tab(src_tab.tab_id()); }