diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-14 05:30:20 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-14 05:30:20 +0300 |
| commit | 226e87306deaba017d36583f51ae34e42b303aad (patch) | |
| tree | 2a1155689b75007c15d93735aedfa58db7a05edf /src/workspace | |
| parent | 17544c36ee397233e2f7b3319d86e3b517e3b5d0 (diff) | |
fix: preserve tab identity across restored sessions
Diffstat (limited to 'src/workspace')
| -rw-r--r-- | src/workspace/aggregate.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/workspace/aggregate.rs b/src/workspace/aggregate.rs index c9c1266d..bf4c9408 100644 --- a/src/workspace/aggregate.rs +++ b/src/workspace/aggregate.rs @@ -48,7 +48,7 @@ impl Tab { let presentation = terminal.effective_presentation(); Some(PaneDetail { pane_id: *id, - tab_idx: self.number.saturating_sub(1), + tab_idx: 0, tab_label: self.display_name(), label: agent_label.clone(), agent_label, @@ -98,7 +98,15 @@ impl Workspace { let multi_tab = self.tabs.len() > 1; self.tabs .iter() - .flat_map(|tab| tab.pane_details(terminals)) + .enumerate() + .flat_map(|(tab_idx, tab)| { + tab.pane_details(terminals) + .into_iter() + .map(move |mut detail| { + detail.tab_idx = tab_idx; + detail + }) + }) .map(|mut detail| { if multi_tab { detail.label = format!("{}ยท{}", detail.tab_label, detail.agent_label); @@ -245,4 +253,27 @@ mod tests { ] ); } + + #[test] + fn pane_details_use_tab_vector_index_not_stable_public_tab_number() { + let mut ws = Workspace::test_new("test"); + let removed_tab = ws.test_add_tab(Some("removed")); + let survivor_tab = ws.test_add_tab(Some("survivor")); + let survivor_pane = ws.tabs[survivor_tab].root_pane; + assert!(ws.close_tab(removed_tab)); + + let mut terminals = HashMap::new(); + let mut terminal = terminal_for_pane(&ws, survivor_pane); + terminal.detected_agent = Some(Agent::Codex); + terminals.insert(terminal.id.clone(), terminal); + + let details = ws.pane_details(&terminals); + let survivor = details + .iter() + .find(|detail| detail.pane_id == survivor_pane) + .expect("surviving tab agent should be listed"); + + assert_eq!(ws.tabs[1].number, 3); + assert_eq!(survivor.tab_idx, 1); + } } |
