From a0ceea1468a72baf4654950cf9d84611e649dd91 Mon Sep 17 00:00:00 2001 From: Marco Arnulfo Date: Fri, 23 Oct 2026 17:16:30 +0200 Subject: [PATCH] Open on the Home tab every launch, as in Excel (fixes #2329) --- apps/gridcraft-web/src/prefs.rs | 2 +- apps/gridcraft/src/main.rs | 2 +- crates/ui-egui/src/lib.rs | 8 +++++++ crates/ui-egui/tests/contextual_ribbon_tab.rs | 22 +++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/apps/gridcraft-web/src/prefs.rs b/apps/gridcraft-web/src/prefs.rs index 7d8c0abf8..987343c56 100644 --- a/apps/gridcraft-web/src/prefs.rs +++ b/apps/gridcraft-web/src/prefs.rs @@ -22,7 +22,7 @@ pub fn restore(app: &mut SheetApp, ui: Option<&str>, prefs: Option<&str>) { { // No usable saved language: keep the browser's, as the desktop keeps the system's. let language = gridcraft_ui_egui::i18n::saved_language(&json).unwrap_or(app.ui.language); - app.ui = state; + app.ui = state.at_startup(); app.ui.language = language; } if let Some(s) = prefs.filter(readable) diff --git a/apps/gridcraft/src/main.rs b/apps/gridcraft/src/main.rs index 7c0eb04e6..6c0d2f676 100644 --- a/apps/gridcraft/src/main.rs +++ b/apps/gridcraft/src/main.rs @@ -111,7 +111,7 @@ fn load_prefs(app: &mut SheetApp) { { let saved = serde_json::from_slice(&b).ok().and_then(|v| gridcraft_ui_egui::i18n::saved_language(&v)); let language = saved.unwrap_or(app.ui.language); - app.ui = ui; + app.ui = ui.at_startup(); app.ui.language = language; } if let Ok(b) = std::fs::read(dir.join("prefs.json")) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index faae9bfae..676359355 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -117,6 +117,14 @@ impl Default for UiState { } impl UiState { + /// The state saved by an earlier run, as the app starts with it. The ribbon tab is written to + /// the preferences but not restored: Excel opens on Home every launch, so a contextual tab + /// (Table Design) cannot come back with nothing selected to justify it. + pub fn at_startup(mut self) -> Self { + self.ribbon_tab = "Home".into(); + self + } + pub fn theme_preference(&self) -> egui::ThemePreference { if self.system_theme { egui::ThemePreference::System diff --git a/crates/ui-egui/tests/contextual_ribbon_tab.rs b/crates/ui-egui/tests/contextual_ribbon_tab.rs index 6e1626dd5..bdd8b5c93 100644 --- a/crates/ui-egui/tests/contextual_ribbon_tab.rs +++ b/crates/ui-egui/tests/contextual_ribbon_tab.rs @@ -72,3 +72,25 @@ fn leaving_the_table_while_on_table_design_returns_to_home() { h.run_steps(2); assert_eq!(h.state().ui.ribbon_tab, "Home"); } + +#[test] +fn startup_opens_on_home_not_the_saved_tab() { + let mut saved = gridcraft_ui_egui::UiState::default(); + saved.ribbon_tab = "Table Design".into(); + saved.dark = true; + let json = serde_json::to_string(&saved).unwrap(); + assert!(json.contains(r#""ribbonTab":"Table Design""#), "{json}"); + let restored = serde_json::from_str::(&json).unwrap().at_startup(); + assert_eq!(restored.ribbon_tab, "Home", "the saved tab is not restored"); + assert!(restored.dark, "the other preferences are"); +} + +#[test] +fn an_ordinary_tab_stays_put_in_a_session() { + let mut session = Session::new(); + session.new_workbook(); + let mut h = harness(session); + h.state_mut().ui.ribbon_tab = "Data".into(); + h.run_steps(3); + assert_eq!(h.state().ui.ribbon_tab, "Data"); +}