diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-12 19:07:07 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-12 19:10:09 +0300 |
| commit | f7a7da03fc27cc6fe4e6a44dabddcd303f939bb9 (patch) | |
| tree | 69a00241e4500703bb723b64dd0060cc83730a0b /src/persist/snapshot.rs | |
| parent | 53429206b736aa0fcfb1c5bfc1c0b11dcca3a059 (diff) | |
fix: stabilize public pane and tab ids
refs #569
Diffstat (limited to 'src/persist/snapshot.rs')
| -rw-r--r-- | src/persist/snapshot.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/persist/snapshot.rs b/src/persist/snapshot.rs index c04c280f..765fa2b6 100644 --- a/src/persist/snapshot.rs +++ b/src/persist/snapshot.rs @@ -57,6 +57,14 @@ pub struct WorkspaceSnapshot { pub identity_cwd: PathBuf, #[serde(default, skip_serializing_if = "Option::is_none")] pub worktree_space: Option<crate::workspace::WorktreeSpaceMembership>, + #[serde(default)] + pub public_pane_numbers: HashMap<u32, usize>, + #[serde(default)] + pub next_public_pane_number: usize, + #[serde(default)] + pub public_tab_numbers: Vec<usize>, + #[serde(default)] + pub next_public_tab_number: usize, pub tabs: Vec<TabSnapshot>, #[serde(default)] pub active_tab: usize, @@ -150,6 +158,10 @@ impl From<LegacyWorkspaceSnapshot> for WorkspaceSnapshot { custom_name: snap.custom_name, identity_cwd, worktree_space: None, + public_pane_numbers: HashMap::new(), + next_public_pane_number: 0, + public_tab_numbers: Vec::new(), + next_public_tab_number: 0, tabs: vec![tab], active_tab: 0, } @@ -284,6 +296,14 @@ fn capture_workspace( .resolved_identity_cwd_from(terminals, terminal_runtimes) .unwrap_or_else(|| ws.identity_cwd.clone()), worktree_space: ws.worktree_space.clone(), + public_pane_numbers: ws + .public_pane_numbers + .iter() + .map(|(pane_id, number)| (pane_id.raw(), *number)) + .collect(), + next_public_pane_number: ws.next_public_pane_number, + public_tab_numbers: ws.tabs.iter().map(|tab| tab.number).collect(), + next_public_tab_number: ws.next_public_tab_number, tabs: ws .tabs .iter() @@ -616,6 +636,10 @@ mod tests { custom_name: Some("pi-mono".to_string()), identity_cwd: PathBuf::from("/home/can/Projects/herdr"), worktree_space: None, + public_pane_numbers: HashMap::from([(0, 1), (1, 2)]), + next_public_pane_number: 3, + public_tab_numbers: vec![1], + next_public_tab_number: 2, tabs: vec![TabSnapshot { custom_name: Some("api".to_string()), layout: LayoutSnapshot::Split { @@ -930,6 +954,30 @@ mod tests { } #[test] + fn capture_contract_tracks_public_id_counters() { + let mut state = state_with_workspaces(&["one"]); + let second = state.workspaces[0].test_split(Direction::Horizontal); + let third = state.workspaces[0].test_split(Direction::Vertical); + let second_tab = state.workspaces[0].test_add_tab(None); + + state.workspaces[0].close_pane(second); + + let snapshot = capture_from_state(&state); + let workspace = &snapshot.workspaces[0]; + assert_eq!( + workspace.public_pane_numbers, + HashMap::from([ + (state.workspaces[0].tabs[0].root_pane.raw(), 1), + (third.raw(), 3), + (state.workspaces[0].tabs[second_tab].root_pane.raw(), 4), + ]) + ); + assert_eq!(workspace.next_public_pane_number, 5); + assert_eq!(workspace.public_tab_numbers, vec![1, 2]); + assert_eq!(workspace.next_public_tab_number, 3); + } + + #[test] fn capture_contract_tracks_workspace_identity_and_pane_cwds() { let mut state = state_with_workspaces(&["one"]); let root = state.workspaces[0].tabs[0].root_pane; @@ -1153,6 +1201,10 @@ mod tests { custom_name: Some("fallback test".to_string()), identity_cwd: PathBuf::from("/tmp"), worktree_space: None, + public_pane_numbers: HashMap::new(), + next_public_pane_number: 0, + public_tab_numbers: Vec::new(), + next_public_tab_number: 0, tabs: vec