Skip to content

Commit

Permalink
keep pane index calculation immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
scauligi committed Sep 18, 2024
1 parent 96b5354 commit 1cc5dc7
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions mux/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub trait Domain: Downcast + Send + Sync {
None => anyhow::bail!("Invalid tab id {}", tab),
};

let mut pane_index = match tab
let pane_index = match tab
.iter_panes_ignoring_zoom()
.iter()
.find(|p| p.pane.pane_id() == pane_id)
Expand Down Expand Up @@ -119,18 +119,6 @@ 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());
}
Expand All @@ -139,7 +127,17 @@ pub trait Domain: Downcast + Send + Sync {
}
};

tab.split_and_insert(pane_index, split_request, Arc::clone(&pane))?;
// pane_index may have changed if src_pane was also in the same tab
let final_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),
};

tab.split_and_insert(final_pane_index, split_request, Arc::clone(&pane))?;
Ok(pane)
}

Expand Down

0 comments on commit 1cc5dc7

Please sign in to comment.