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 <[email protected]>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-10-25 21:54:36 -06:00
1 parent 59cb4c49bd
commit d1c875072a
5 files changed
+41

No files matched your search

+3
View File
@@ -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<String, Value>,
+20
View File
@@ -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");
}
+16
View File
@@ -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;
}
}
+1
View File
@@ -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
+1
View File
@@ -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);