diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 8142b558a8..663ce32b90 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -652,8 +652,10 @@ impl VectorcraftApp { // panel (Show on Shape Creation). panels::transform::show_on_shape_creation(self, &ctx); crate::toasts::show(self, &ctx); - // A `prefs.reset` run in this pass outside `Self::run`. - crate::prefs_dialog::apply_prefs_resets(self); + // A `prefs.reset` run in this pass outside `Self::run`; the next pass draws the reset rows. + if crate::prefs_dialog::apply_prefs_resets(self) { + ctx.request_repaint(); + } // After every panel had its chance to draw in this pass. crate::panels::three_d::end_stale_drag(self, &ctx); if self.custom_titlebar { diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs index 70d7bc5d5f..0f777a9dca 100644 --- a/crates/ui-egui/src/prefs_dialog.rs +++ b/crates/ui-egui/src/prefs_dialog.rs @@ -225,10 +225,11 @@ pub fn confirm(app: &mut VectorcraftApp) -> Result { let touch_ws = values.get("touchWorkspace").and_then(Value::as_bool); let document_units = d.fields.get(RESET_UNITS).is_none_or(|v| values.get("unitsGeneral") != Some(v)); app.run("prefs.set", json!({ "values": values, "documentUnits": document_units }))?; - // Outside an automatic Touch switch, the task bar is set before OK can enter the Touch - // workspace, so it goes to the workspace being left; during one, after OK leaves it. + // When OK enters the Touch workspace, the task bar is set before the switch, so it goes to the + // workspace being left; otherwise after it, so a return from Touch gives it to the workspace + // returned to. let task_bar = d.fields.get("__taskBar").and_then(Value::as_bool); - let before_switch = app.ui.touch_workspace_restore.is_none(); + let before_switch = touch_ws.is_some() && crate::workspaces::enters_touch(app, app.touch_screen); if before_switch && let Some(on) = task_bar { app.ui.task_bar = on; } @@ -517,10 +518,11 @@ fn default_ui_fields(ui: &crate::UiState) -> [(&'static str, bool); 3] { /// After `prefs.reset`, alone or as a batch step, of every category or of one: the UI-only rows /// ([`UI_FIELDS`]) and the Edit Original app of the categories it reset take their defaults too. -pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) { +/// Returns whether any reset was pending. +pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) -> bool { let resets = app.session.take_prefs_resets(); if resets.is_empty() { - return; + return false; } let in_reset = |category: &str| resets.iter().any(|r| r.is_none_or(|c| c == category)); for (key, value) in default_ui_fields(&app.ui) { @@ -536,6 +538,7 @@ pub(crate) fn apply_prefs_resets(app: &mut VectorcraftApp) { if vectorcraft_engine::cmd::prefscmds::spec("editOriginalSystemDefaults").is_some_and(|s| in_reset(s.category)) { crate::original_editor::reset_saved(app); } + true } /// The height of the fields column under the category's name: the field list, the gap and the diff --git a/crates/ui-egui/src/prefs_dialog/tests.rs b/crates/ui-egui/src/prefs_dialog/tests.rs index 0074301e7d..05720a2e26 100644 --- a/crates/ui-egui/src/prefs_dialog/tests.rs +++ b/crates/ui-egui/src/prefs_dialog/tests.rs @@ -620,6 +620,26 @@ fn ok_sets_the_task_bar_in_the_workspace_outside_touch() { assert!(touch.task_bar, "Touch keeps its own task bar"); } +/// A Touch return marker left over from an earlier automatic switch (Window › Workspace does not +/// clear it) does not change where OK puts the task bar: OK enters Touch from the workspace it +/// leaves, so that workspace takes the row and Touch keeps its own. +#[test] +fn ok_sets_the_task_bar_in_the_workspace_left_with_a_stale_touch_marker() { + let mut a = app(); + a.touch_screen = true; + a.run("prefs.set", json!({"key": "touchWorkspace", "value": false})).unwrap(); + a.ui.touch_workspace_restore = Some("Typography".into()); + crate::workspaces::switch(&mut a.ui, "Essentials Classic").unwrap(); + a.ui.task_bar = true; + open(&mut a, Some("General")); + reset_preferences(&mut a); + confirm(&mut a).unwrap(); + assert_eq!(a.ui.workspace, crate::workspaces::TOUCH); + assert!(a.ui.task_bar, "Touch keeps its own task bar"); + let classic = a.ui.workspace_changes.iter().find(|w| w.name == "Essentials Classic").unwrap(); + assert!(!classic.task_bar, "the workspace left takes the reset value"); +} + /// A `prefs.reset` run straight on the session, outside `VectorcraftApp::run`, resets the UI-only /// rows by the end of the next frame. #[test] diff --git a/crates/ui-egui/src/workspaces.rs b/crates/ui-egui/src/workspaces.rs index a1c7464866..a974d13358 100644 --- a/crates/ui-egui/src/workspaces.rs +++ b/crates/ui-egui/src/workspaces.rs @@ -170,6 +170,11 @@ pub fn builtins() -> Vec { ] } +/// Whether [`sync_touch_workspace`] with `touch_screen` switches to the Touch workspace. +pub fn enters_touch(app: &VectorcraftApp, touch_screen: bool) -> bool { + app.session.prefs.touch_workspace && touch_screen && app.ui.workspace != TOUCH +} + /// Preferences › Devices › Enable Touch Workspace (#394): on, a touch screen switches to the Touch /// workspace; off, or when no touch screen is reported, the workspace before that switch is /// restored if Touch was entered automatically. Each switch keeps the layout it leaves and brings