From d1c875072ae5846ca0b0cf331d13365afebbb395 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 21:54:36 -0600 Subject: [PATCH] fix(ui): the Color panel remembers its options across restarts (#9592) The Color panel's mode, ramp, Web-safe ramp and edited chip were never saved, so every launch reset them. They now live in the preferences (colorPanel), written when they change and restored at launch next to the dock layout, independent of workspaces. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/prefs.rs | 3 +++ crates/ui-egui/src/color_panel_tests.rs | 20 ++++++++++++++++++++ crates/ui-egui/src/color_panel_ui.rs | 16 ++++++++++++++++ crates/ui-egui/src/panels.rs | 1 + crates/ui-egui/src/prefs_ui.rs | 1 + 5 files changed, 41 insertions(+) diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs index 1525741a5e..49bbc19629 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine/src/prefs.rs @@ -1088,6 +1088,9 @@ pub struct Preferences { /// as the user changes it and restored at launch when Workspace › Remember Workspace /// Changes is on. JSON owned by the shell. pub panel_layout: Value, + /// The Color panel's options (what it shows, its ramp, Web colors, which chip it edits), + /// kept across restarts as Photoshop keeps them. JSON owned by the shell. + pub color_panel: Value, /// The last choices of dialogs that remember them across restarts, by command id (Edit › /// Fill…: `"edit.fill"` → its params). JSON owned by the shell. pub dialogs: BTreeMap, diff --git a/crates/ui-egui/src/color_panel_tests.rs b/crates/ui-egui/src/color_panel_tests.rs index 6f7cc49729..902e51f748 100644 --- a/crates/ui-egui/src/color_panel_tests.rs +++ b/crates/ui-egui/src/color_panel_tests.rs @@ -500,3 +500,23 @@ fn every_slider_mode_recolours_the_selected_shape() { assert_eq!(shape_fill(h.state()), [255, 255, 255], "{mode:?}"); } } + +/// #9592: the Color panel's options survive a restart (they ride in the preferences), as in +/// Photoshop; preferences without them keep the defaults. +#[test] +fn color_panel_options_survive_a_restart() { + let mut first = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + first.ui.color_panel.mode = ColorPanelMode::HsbSliders; + first.ui.color_panel.ramp = ColorRamp::GrayscaleRamp; + crate::color_panel_ui::persist(&mut first); + let saved = first.session.prefs().clone(); + + let mut next = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + next.session.prefs.edit(|p| *p = saved); + crate::color_panel_ui::restore(&mut next); + assert_eq!((next.ui.color_panel.mode, next.ui.color_panel.ramp), (ColorPanelMode::HsbSliders, ColorRamp::GrayscaleRamp)); + + let mut fresh = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + crate::color_panel_ui::restore(&mut fresh); + assert_eq!(fresh.ui.color_panel.mode, ColorPanelMode::HueCube, "no saved options: the default"); +} diff --git a/crates/ui-egui/src/color_panel_ui.rs b/crates/ui-egui/src/color_panel_ui.rs index 19f223b8a2..29553fead2 100644 --- a/crates/ui-egui/src/color_panel_ui.rs +++ b/crates/ui-egui/src/color_panel_ui.rs @@ -764,3 +764,19 @@ pub(crate) fn panel_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) { ui.separator(); ramp_menu(app, ui); } + +/// Remember the Color panel's options in the preferences when they change, so they survive a +/// restart (#9592). Cheap: a small JSON compare per frame. +pub fn persist(app: &mut PhotocraftApp) { + let Ok(now) = serde_json::to_value(app.ui.color_panel) else { return }; + if app.session.prefs().color_panel != now { + app.session.prefs.edit(|p| p.color_panel = now); + } +} + +/// Restore the remembered Color panel options at launch; unreadable ones keep the defaults. +pub fn restore(app: &mut PhotocraftApp) { + if let Ok(c) = serde_json::from_value(app.session.prefs().color_panel.clone()) { + app.ui.color_panel = c; + } +} diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index b86d7b2af9..1f76a0f90f 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -1868,6 +1868,7 @@ pub fn dock_area(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } egui::CentralPanel::default().frame(egui::Frame::NONE).show(ui, |ui| crate::panel_docking::show(app, ui)); crate::dock::persist(app, ui.ctx()); + crate::color_panel_ui::persist(app); } /// The docking layout's protected canvas panel: the document area, with the icon rail on its end diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rs index 68ebf5bd97..2369b38fd1 100644 --- a/crates/ui-egui/src/prefs_ui.rs +++ b/crates/ui-egui/src/prefs_ui.rs @@ -250,6 +250,7 @@ pub fn load(app: &mut PhotocraftApp) { } } crate::dock::restore(app); + crate::color_panel_ui::restore(app); crate::brush_picker::restore(app); crate::last_brush::restore(app); sync_rulers(app);