diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rs index 8a7745c5d0..41b42bfd60 100644 --- a/crates/ui-egui/src/panels/swatches.rs +++ b/crates/ui-egui/src/panels/swatches.rs @@ -224,7 +224,7 @@ pub(crate) fn sole_selected_group(app: &VectorcraftApp) -> Option { } /// Command `id` ran with `params` and replied `reply`: a color group that `swatch.renameGroup` -/// renamed stays selected in the panel under its new name, and Shift-click still extends the +/// or `swatch.editGroup` renamed stays selected in the panel under its new name, and Shift-click still extends the /// selection from it. Ungroup Color Group and Delete Swatch take the names they removed out of the /// selection, so a group that later takes such a name is not selected in its place. The steps of a /// `command.batch` are followed in order up to the first step that is not one of [`KEEPS_GROUPS`]: @@ -242,7 +242,7 @@ pub(crate) fn after_command(ctx: &egui::Context, id: &str, params: &Value, reply } }; match id { - "swatch.renameGroup" => { + "swatch.renameGroup" | "swatch.editGroup" => { if let (Some(old), Some(new)) = (params["group"].as_str(), reply["name"].as_str()) { rename(old, Some(new)); } @@ -287,6 +287,8 @@ const KEEPS_GROUPS: &[&str] = &[ "swatch.duplicate", "swatch.addUsedColors", "swatch.sortByKind", + "swatch.sortByName", + "swatch.editGroup", "swatch.spotOptions", "swatch.setSpot", "swatch.list", diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index c2ab42c356..d42d634259 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -1529,6 +1529,32 @@ fn a_batch_moves_the_selection_only_with_its_group() { assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), (vec!["Brights".to_string()], "Brights".to_string())); } +/// Sort by Name keeps the groups, so a rename after it in a batch still moves the selection, and +/// Edit Color Group's `rename` moves it as Color Group Options does, alone or in a batch. +#[test] +fn the_selection_follows_sorting_and_group_edits() { + let mut app = app(); + let ctx = context(); + app.ui_ctx = Some(ctx.clone()); + set_pstate(&ctx, "swatch-selected", vec!["Brights".to_string()]); + set_pstate(&ctx, "swatch-anchor", "Brights".to_string()); + let follows = |name: &str| (vec![name.to_string()], name.to_string()); + let steps = json!([ + {"command": "swatch.sortByName", "params": {}}, + {"command": "swatch.renameGroup", "params": {"group": "Brights", "name": "Vivid"}}, + ]); + app.run("command.batch", json!({"commands": steps})).unwrap(); + assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), follows("Vivid"), "Sort by Name"); + app.run("swatch.editGroup", json!({"group": "Vivid", "colors": ["#ff0000"], "rename": "Bold"})).unwrap(); + assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), follows("Bold"), "Edit Color Group"); + let steps = json!([ + {"command": "swatch.editGroup", "params": {"group": "Bold", "colors": ["#00ff00"], "rename": "Loud"}}, + {"command": "swatch.renameGroup", "params": {"group": "Loud", "name": "Calm"}}, + ]); + app.run("command.batch", json!({"commands": steps})).unwrap(); + assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), follows("Calm"), "Edit Color Group in a batch"); +} + /// The panel menu's Show Recent Colors hides and shows the panel's Recent Colors row (#6617): /// checked by default, applied colors still join the list while the row is hidden, and the Color /// panel keeps its own row and setting.