From 81de0f6fbf4df9591b87f9b5b5157e2bbf29401c Mon Sep 17 00:00:00 2001 From: gorkematlyn Date: Tue, 20 Oct 2026 22:28:47 +0000 Subject: [PATCH] UI.7: keep the newest remembered layout when the list is full remember() pushed the layout being left and then truncated the list to 64, so with 64 workspaces already remembered it dropped the entry it had just pushed and the changes were lost. Drop the oldest entries instead; a test fills the list and checks the last one left survives. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KcHisW1vt6pkVPYbzL6Cpg --- crates/ui-egui/src/workspaces.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/workspaces.rs b/crates/ui-egui/src/workspaces.rs index 869715914..5606bd94b 100644 --- a/crates/ui-egui/src/workspaces.rs +++ b/crates/ui-egui/src/workspaces.rs @@ -223,7 +223,9 @@ fn remember(ui: &mut UiState) { let w = capture(ui, ¤t); ui.workspace_changes.retain(|x| x.name != current); ui.workspace_changes.push(w); - ui.workspace_changes.truncate(64); + // Over the cap, the oldest go: the layout just kept is the newest. + let over = ui.workspace_changes.len().saturating_sub(64); + ui.workspace_changes.drain(..over); } /// Switch to workspace `name` as it was left (its changes since it was saved), else as saved. @@ -603,6 +605,24 @@ mod tests { assert!(!ui.control_bar, "Essentials didn't remember the deleted workspace's layout"); } + #[test] + fn a_full_list_of_remembered_layouts_drops_the_oldest_not_the_newest() { + let mut ui = UiState::default(); + let names: Vec = (0..70).map(|i| format!("W{i}")).collect(); + for name in &names { + save_as(&mut ui, name).unwrap(); + } + for name in &names { + switch(&mut ui, name).unwrap(); + ui.control_bar = true; + } + switch(&mut ui, ESSENTIALS).unwrap(); + assert_eq!(ui.workspace_changes.len(), 64); + assert!(ui.workspace_changes.iter().all(|w| w.name != "W0"), "the oldest went"); + switch(&mut ui, "W69").unwrap(); + assert!(ui.control_bar, "the layout just left is kept"); + } + #[test] fn saving_a_workspace_moves_the_changes_into_it() { let mut ui = UiState { control_bar: true, ..Default::default() };