From 59752f7ebfee542f3d86e125f25e927b1fd9f8b1 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 16:58:21 -0800 Subject: [PATCH] Swatches: Color Group Options renames only the group it opened on OK closes the dialog and renames nothing when another document has become the active one, or when the color group at the group's place in the list no longer has the name and swatches the dialog opened with. swatch.renameGroup makes a drag still in progress an undo step of its own first, so canceling or undoing the drag leaves the rename. ui.colorGroupOptions without group opens on the color group selected alone in the Swatches panel, as long as the panel's selection still belongs to the active document and art. The panel's selection follows renames in a command.batch only up to the first step that may switch documents or replace a group. Ungroup Color Group and Delete Swatch take the names they removed out of the selection. The es catalog had the missing `group` and no colour group `{group}` rows twice after the last merge of main; the duplicates are removed. --- crates/engine/src/cmd/swatch.rs | 6 +- crates/engine/src/tests/swatchcmds.rs | 18 ++++ crates/mcp/src/ui_catalog.rs | 2 +- .../src/dialogs/color_group_options.rs | 83 +++++++++++++++++-- crates/ui-egui/src/i18n/es.tsv | 2 - crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panels/swatches.rs | 72 ++++++++++++++-- crates/ui-egui/src/panels/swatches/actions.rs | 2 +- crates/ui-egui/src/panels/swatches/body.rs | 8 ++ crates/ui-egui/src/panels/swatches/tests.rs | 70 ++++++++++++++++ docs/control-protocol.md | 8 +- docs/mcp.md | 2 +- 12 files changed, 248 insertions(+), 27 deletions(-) diff --git a/crates/engine/src/cmd/swatch.rs b/crates/engine/src/cmd/swatch.rs index 514e96f0c6..76003551cd 100644 --- a/crates/engine/src/cmd/swatch.rs +++ b/crates/engine/src/cmd/swatch.rs @@ -113,7 +113,7 @@ pub fn specs() -> Vec { "Color Group Options", ["Window", "Swatches"], None, - "{group: color group, name: its new name (trimmed)} rename a color group, as one undo step; its swatches, their colors and the art linked to them stay as they are. Swatches and color groups share one set of names, so a name another color group or a swatch has is an error, as is an empty name; the group's own name records no undo step → {name}", + "{group: color group, name: its new name (trimmed)} rename a color group, as one undo step; its swatches, their colors and the art linked to them stay as they are. Swatches and color groups share one set of names, so a name another color group or a swatch has is an error, as is an empty name; the group's own name records no undo step. A drag still in progress becomes an undo step of its own first → {name}", has_doc, swatch_rename_group ), @@ -1228,6 +1228,10 @@ fn swatch_rename_group(s: &mut Session, p: &Value) -> Result { if d.swatch_name_taken(&name) { return Err(bad(C, format!("a swatch or color group named `{name}` already exists"))); } + // A drag still in progress is a step of its own, so canceling or undoing it leaves the rename. + if !s.previewing && s.batch_stash.is_none() && s.in_interaction() { + super::settle_interaction(s)?; + } s.edit("Color Group Options", |d, _| { let g = d.swatch_groups.iter_mut().find(|g| g.name == group).ok_or_else(|| bad(C, format!("no colour group `{group}`")))?; g.name.clone_from(&name); diff --git a/crates/engine/src/tests/swatchcmds.rs b/crates/engine/src/tests/swatchcmds.rs index 2cd176f9be..1b87639ef9 100644 --- a/crates/engine/src/tests/swatchcmds.rs +++ b/crates/engine/src/tests/swatchcmds.rs @@ -617,6 +617,24 @@ fn rename_group_renames_only_the_group_in_one_undo_step() { } } +/// A color group renamed while a drag is still in progress keeps its new name when the drag is +/// canceled: the drag becomes a step of its own first, and the rename is the next step. +#[test] +fn rename_group_during_a_drag_is_a_step_of_its_own() { + let mut s = session(); + rect_filled(&mut s, json!({"swatch": "Bright Red"})); + let undo = undo_len(&s); + s.begin_interaction("Move").unwrap(); + s.preview("object.move", &json!({"dx": 7, "dy": 0})).unwrap(); + run(&mut s, "swatch.renameGroup", json!({"group": "Brights", "name": "Vivid"})); + s.cancel_interaction().ok(); + assert!(doc(&s).swatch_groups.iter().any(|g| g.name == "Vivid"), "canceling the drag keeps the rename"); + assert_eq!(undo_len(&s), undo + 2, "the drag and the rename are two steps"); + run(&mut s, "edit.undo", json!({})); + assert!(doc(&s).swatch_groups.iter().any(|g| g.name == "Brights"), "Undo takes back the rename alone"); + assert_eq!(undo_len(&s), undo + 1); +} + #[test] fn a_cmyk_document_starts_with_cmyk_swatches_and_stores_new_colours_as_cmyk() { use vectorcraft_color::Color; diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 2b7a9ae5aa..9befb15273 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1000,7 +1000,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorGroupOptions", "Color Group Options…", "", - "{group} open Color Group Options for that color group (dialog `colorGroupOptions`, field `name`): OK renames the group (engine: swatch.renameGroup); a name that is empty or that another color group or a swatch has keeps the dialog open", + "{group?} open Color Group Options for that color group, or without group for the color group selected alone in the Swatches panel (dialog `colorGroupOptions`, field `name`): OK renames the group (engine: swatch.renameGroup); a name that is empty or that another color group or a swatch has keeps the dialog open; when another document is active, or the color group at the group's place in the list no longer has the name and swatches it opened with, OK closes the dialog and renames nothing", ), ( "ui.colorPicker", diff --git a/crates/ui-egui/src/dialogs/color_group_options.rs b/crates/ui-egui/src/dialogs/color_group_options.rs index 706bab65c0..101b5496a3 100644 --- a/crates/ui-egui/src/dialogs/color_group_options.rs +++ b/crates/ui-egui/src/dialogs/color_group_options.rs @@ -2,7 +2,9 @@ //! (`swatch.renameGroup`) and keeps it selected in the panel; its swatches and their colors stay //! as they are. //! -//! Fields: `name` and `__group` (the group being renamed). +//! Fields: `name`, `__group` (the group being renamed), `__swatches` (the names of its swatches +//! when the dialog opened), `__index` (its place in the list of color groups) and `__doc` (the uid +//! of its document). use serde_json::{Value, json}; @@ -17,20 +19,45 @@ pub const KIND: &str = "colorGroupOptions"; pub(super) const SPEC: DialogSpec = DialogSpec { heading: |_| tl!("Color Group Options").into(), body, confirm, min_width: 320.0, ..DialogSpec::FORM }; -/// `ui.colorGroupOptions {group}`: open Color Group Options for color group `group`. +/// The field that holds the uid of the document the dialog opened on. +const DOC: &str = "__doc"; + +/// The field that holds the names of the group's swatches when the dialog opened. +const SWATCHES: &str = "__swatches"; + +/// The field that holds the group's place in the document's list of color groups. +const INDEX: &str = "__index"; + +/// `ui.colorGroupOptions {group?}`: open Color Group Options for color group `group`, or without +/// `group` for the color group selected alone in the Swatches panel. pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { let key = "group"; let group = match p.get(key) { - Some(Value::String(g)) => g.as_str(), - None | Some(Value::Null) => return Err("missing `group`".into()), + Some(Value::String(g)) => g.clone(), + None | Some(Value::Null) => crate::panels::swatches::sole_selected_group(app).ok_or("missing `group`")?, Some(_) => return Err(format!("`{key}` must be a string")), }; - let d = &app.session.active().ok_or("no document open")?.doc; - let name = d.swatch_groups.iter().find(|g| g.name == group).ok_or_else(|| format!("no colour group `{group}`"))?.name.clone(); - app.ui.dialog = Some(Dialog::new(KIND, json!({ "name": name, "__group": name }))); + let st = app.session.active().ok_or("no document open")?; + let at = st.doc.swatch_groups.iter().position(|g| g.name == group).ok_or_else(|| format!("no colour group `{group}`"))?; + let g = &st.doc.swatch_groups[at]; + let swatches: Vec<&str> = g.swatches.iter().map(|w| w.name.as_str()).collect(); + let fields = json!({ "name": g.name.clone(), "__group": g.name.clone(), SWATCHES: swatches, INDEX: at, DOC: st.uid }); + app.ui.dialog = Some(Dialog::new(KIND, fields)); Ok(Value::Null) } +/// Whether the dialog's group is still in its document, at the place in the list, under the name +/// and with the swatches it opened with, and that document is the active one. +fn same_group(app: &VectorcraftApp, d: &Dialog) -> bool { + let Some(st) = app.session.active().filter(|st| d.fields.get(DOC).and_then(Value::as_u64) == Some(st.uid)) else { return false }; + let at = d.fields.get(INDEX).and_then(Value::as_u64).and_then(|i| usize::try_from(i).ok()); + let opened: Vec<&str> = + d.fields.get(SWATCHES).and_then(Value::as_array).map(|a| a.iter().filter_map(Value::as_str).collect()).unwrap_or_default(); + let group = d.str("__group"); + at.and_then(|i| st.doc.swatch_groups.get(i)) + .is_some_and(|g| g.name == group && g.swatches.iter().map(|w| w.name.as_str()).eq(opened.iter().copied())) +} + fn body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { grid(ui, |ui| { label(ui, tl!("Name:")); @@ -41,8 +68,15 @@ fn body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { } /// OK: rename the group (the Swatches panel keeps it selected, [`crate::panels::swatches::after_command`]). -/// A name that is empty or that another group or a swatch has keeps the dialog open. +/// A name that is empty or that another group or a swatch has keeps the dialog open. When another +/// document has become the active one, or the color group at the group's place in the list no +/// longer has the name and swatches it opened with, it closes as Cancel does and renames nothing. +/// Color groups carry nothing else to tell them apart. fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { + if !same_group(app, d) { + app.ui.dialog = None; + return Ok(json!({})); + } let r = app.run("swatch.renameGroup", json!({ "group": d.str("__group"), "name": d.str("name") })); if r.is_ok() { app.ui.dialog = None; @@ -112,4 +146,37 @@ mod tests { assert!(app.run("ui.colorGroupOptions", json!({})).is_err()); assert!(app.run("ui.colorGroupOptions", json!({"group": 5})).is_err()); } + + /// OK closes the dialog and renames nothing when another document has become the active one, + /// or when another group took the name of the group it opened on while it was open. + #[test] + fn renames_only_the_group_it_opened_on() { + let mut app = app(); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.run("document.activate", json!({"index": 0})).unwrap(); + app.run("ui.colorGroupOptions", json!({"group": "Brights"})).unwrap(); + app.run("document.activate", json!({"index": 1})).unwrap(); + set(&mut app, "Vivid"); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert!(groups(&app).contains(&"Brights".to_string()), "the document made active keeps its group"); + app.run("document.activate", json!({"index": 0})).unwrap(); + assert!(groups(&app).contains(&"Brights".to_string()), "the group it opened on keeps its name"); + // Its group ungrouped, and another group renamed to its name. + app.run("ui.colorGroupOptions", json!({"group": "Brights"})).unwrap(); + app.run("swatch.ungroup", json!({"name": "Brights"})).unwrap(); + app.run("swatch.renameGroup", json!({"group": "Grays", "name": "Brights"})).unwrap(); + set(&mut app, "Vivid"); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert!(groups(&app).contains(&"Brights".to_string()) && !groups(&app).contains(&"Vivid".to_string())); + // Its group moved to another place in the list. + app.run("swatch.newGroup", json!({"name": "Extra", "swatches": ["White"]})).unwrap(); + let first = groups(&app)[0].clone(); + app.run("ui.colorGroupOptions", json!({"group": first})).unwrap(); + app.run("swatch.move", json!({"names": [first]})).unwrap(); + set(&mut app, "Vivid"); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none() && groups(&app).contains(&first) && !groups(&app).contains(&"Vivid".to_string())); + } } diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 3730c2320c..3600f7569a 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -5077,8 +5077,6 @@ liquify-list-end {0}, {1} {0}, {1} @msg a gradient needs at least two stops un degradado necesita al menos dos paradas @msg a graphic style named `{to}` already exists ya existe un estilo gráfico llamado `{to}` @msg a swatch or color group named `{name}` already exists ya existe una muestra o un grupo de colores llamado `{name}` -@msg missing `group` falta `group` -@msg no colour group `{group}` no existe el grupo de colores `{group}` @msg a key object sits on that point hay un objeto clave en ese punto @msg a page is missing falta una página @msg a page out of range una página fuera de rango diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index e4068e9452..d040a529ba 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1001,7 +1001,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.colorGroupOptions", "Color Group Options…", "", - "{group} open Color Group Options for that color group (dialog `colorGroupOptions`, field `name`): OK renames the group (engine: swatch.renameGroup); a name that is empty or that another color group or a swatch has keeps the dialog open", + "{group?} open Color Group Options for that color group, or without group for the color group selected alone in the Swatches panel (dialog `colorGroupOptions`, field `name`): OK renames the group (engine: swatch.renameGroup); a name that is empty or that another color group or a swatch has keeps the dialog open; when another document is active, or the color group at the group's place in the list no longer has the name and swatches it opened with, OK closes the dialog and renames nothing", ), ( "ui.colorPicker", diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rs index e3d1930bc5..8a7745c5d0 100644 --- a/crates/ui-egui/src/panels/swatches.rs +++ b/crates/ui-egui/src/panels/swatches.rs @@ -212,33 +212,87 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { body(app, ui, TILE); } +/// The color group selected alone in the panel (what Color Group Options opens on), if any. +pub(crate) fn sole_selected_group(app: &VectorcraftApp) -> Option { + let (ctx, st) = (app.ui_ctx.as_ref()?, app.session.active()?); + if !body::selection_is_current(app, ctx) { + return None; + } + let mut sel: Vec = pstate(ctx, "swatch-selected"); + sel.retain(|n| n == REGISTRATION || st.doc.swatch_name_taken(n)); + actions::sole_group(app, &sel) +} + /// 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 -/// selection from it. The steps of a `command.batch` are followed in order. +/// 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`]: +/// such a step may switch documents or replace a group, and the selection stays as it is from there. pub(crate) fn after_command(ctx: &egui::Context, id: &str, params: &Value, reply: &Value) { + let rename = |old: &str, new: Option<&str>| { + let mut sel: Vec = pstate(ctx, "swatch-selected"); + match new { + Some(new) => sel.iter_mut().filter(|n| *n == old).for_each(|n| *n = new.to_string()), + None => sel.retain(|n| n != old), + } + set_pstate(ctx, "swatch-selected", sel); + if pstate::(ctx, "swatch-anchor") == old { + set_pstate(ctx, "swatch-anchor", new.unwrap_or_default().to_string()); + } + }; match id { "swatch.renameGroup" => { - let (Some(old), Some(new)) = (params["group"].as_str(), reply["name"].as_str()) else { return }; - let mut sel: Vec = pstate(ctx, "swatch-selected"); - for n in sel.iter_mut().filter(|n| *n == old) { - *n = new.to_string(); + if let (Some(old), Some(new)) = (params["group"].as_str(), reply["name"].as_str()) { + rename(old, Some(new)); } - set_pstate(ctx, "swatch-selected", sel); - if pstate::(ctx, "swatch-anchor") == old { - set_pstate(ctx, "swatch-anchor", new.to_string()); + } + "swatch.ungroup" => { + if let Some(name) = params["name"].as_str() { + rename(name, None); + } + } + "swatch.delete" => { + let names = params["names"].as_array().map(Vec::as_slice).unwrap_or_default(); + for name in names.iter().chain(std::iter::once(¶ms["name"])).filter_map(Value::as_str) { + rename(name, None); } } "command.batch" => { let steps = params["commands"].as_array().map(Vec::as_slice).unwrap_or_default(); let results = reply["results"].as_array().map(Vec::as_slice).unwrap_or_default(); for (step, r) in steps.iter().zip(results) { - after_command(ctx, step["command"].as_str().unwrap_or_default(), &step["params"], r); + let id = step["command"].as_str().unwrap_or_default(); + if !KEEPS_GROUPS.contains(&id) { + break; + } + after_command(ctx, id, &step["params"], r); } } _ => {} } } +/// The batch steps the panel's selection follows: they act on the active document only, and +/// remove no color group except the ones they name. +const KEEPS_GROUPS: &[&str] = &[ + "swatch.renameGroup", + "swatch.ungroup", + "swatch.delete", + "swatch.new", + "swatch.newGroup", + "swatch.edit", + "swatch.move", + "swatch.merge", + "swatch.duplicate", + "swatch.addUsedColors", + "swatch.sortByKind", + "swatch.spotOptions", + "swatch.setSpot", + "swatch.list", + "swatch.unused", +]; + /// Item actions target the clicked swatch, independently of the paint or other selected chips. fn item_context_menu(app: &mut VectorcraftApp, ui: &Ui, resp: &Response, e: &Entry) { if e.is_folder() { diff --git a/crates/ui-egui/src/panels/swatches/actions.rs b/crates/ui-egui/src/panels/swatches/actions.rs index 75460e8791..812a3ffb33 100644 --- a/crates/ui-egui/src/panels/swatches/actions.rs +++ b/crates/ui-egui/src/panels/swatches/actions.rs @@ -35,7 +35,7 @@ pub(super) fn selected_group(app: &VectorcraftApp, sel: &[String]) -> Option Option { +pub(super) fn sole_group(app: &VectorcraftApp, sel: &[String]) -> Option { match sel { [_] => selected_group(app, sel), _ => None, diff --git a/crates/ui-egui/src/panels/swatches/body.rs b/crates/ui-egui/src/panels/swatches/body.rs index bcecabb20c..944a245b9e 100644 --- a/crates/ui-egui/src/panels/swatches/body.rs +++ b/crates/ui-egui/src/panels/swatches/body.rs @@ -197,6 +197,14 @@ pub(super) fn focus_swatch(app: &VectorcraftApp, ui: &Ui, active: Option<&str>) active.filter(|_| changed).map(str::to_string) } +/// Whether the panel's selection is still the one it showed last: neither another document nor +/// other art has been selected since, which [`focus_swatch`] clears it for on the next frame. +pub(super) fn selection_is_current(app: &VectorcraftApp, ctx: &egui::Context) -> bool { + let art: Option = app.session.active().map(|st| (st.uid, st.selection.objects.iter().map(|id| id.0).collect())); + let (last_art, _): (Option>, Option) = pstate(ctx, "swatch-focus"); + last_art.is_none_or(|l| l == art) +} + /// The swatch the active paint comes from: a linked colour's global swatch (a tint's tint swatch /// when there is one), a process colour's swatch of that colour (a colour no swatch has: none, so /// text in a colour of its own highlights nothing), a gradient's gradient swatch, or None; nothing diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index a903533b4e..c2ab42c356 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -1459,6 +1459,76 @@ fn color_group_options_opens_on_a_sole_selected_group() { assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), (vec!["Ash".to_string()], "Ash".to_string())); } +/// Color Group Options from the command palette (no `group`) opens on the color group selected +/// alone in the panel; without one it opens nothing and reports the missing group. +#[test] +fn color_group_options_without_a_group_opens_on_the_selected_group() { + let mut app = app(); + let ctx = context(); + app.ui_ctx = Some(ctx.clone()); + for sel in [vec![], vec!["Red"], vec!["Brights", "Grays"]] { + set_pstate(&ctx, "swatch-selected", sel.iter().map(|s| s.to_string()).collect::>()); + assert!(app.run("ui.colorGroupOptions", json!({})).is_err() && app.ui.dialog.is_none(), "{sel:?}"); + } + set_pstate(&ctx, "swatch-selected", vec!["Grays".to_string()]); + app.run("ui.colorGroupOptions", json!({})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().map(|d| d.str("__group")).as_deref(), Some("Grays")); + crate::dialogs::cancel(&mut app); + // The panel showed the selection in this document; another document made active since then + // does not take it. + let uid = app.session.active().unwrap().uid; + set_pstate(&ctx, "swatch-focus", (Some(Some((uid, Vec::::new()))), None::)); + app.run("ui.colorGroupOptions", json!({})).unwrap(); + crate::dialogs::cancel(&mut app); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + assert!(app.run("ui.colorGroupOptions", json!({})).is_err() && app.ui.dialog.is_none(), "another document"); +} + +/// Renames in a batch move the selection to another group neither after an Ungroup of the +/// selected group nor in another document; a batch step that keeps the groups (Sort by Kind) does +/// not stop the selection from following a rename, and Delete Swatch on the group ends it. +#[test] +fn a_batch_moves_the_selection_only_with_its_group() { + let mut app = app(); + let ctx = context(); + app.ui_ctx = Some(ctx.clone()); + let select = |sel: &str| { + set_pstate(&ctx, "swatch-selected", vec![sel.to_string()]); + set_pstate(&ctx, "swatch-anchor", sel.to_string()); + }; + select("Brights"); + let steps = json!([ + {"command": "swatch.ungroup", "params": {"name": "Brights"}}, + {"command": "swatch.renameGroup", "params": {"group": "Grays", "name": "Brights"}}, + {"command": "swatch.renameGroup", "params": {"group": "Brights", "name": "Vivid"}}, + ]); + app.run("command.batch", json!({"commands": steps})).unwrap(); + assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), (Vec::::new(), String::new()), "Ungroup ends the selection"); + // A step that keeps the groups, then a rename of the selected group. + select("Vivid"); + let steps = json!([ + {"command": "swatch.sortByKind", "params": {}}, + {"command": "swatch.renameGroup", "params": {"group": "Vivid", "name": "Bold"}}, + ]); + app.run("command.batch", json!({"commands": steps})).unwrap(); + assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), (vec!["Bold".to_string()], "Bold".to_string())); + app.run("swatch.delete", json!({"name": "Bold"})).unwrap(); + assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), (Vec::::new(), String::new()), "Delete Swatch ends the selection"); + // Brights selected in one new document, renamed in another. + for _ in 0..2 { + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + } + app.run("document.activate", json!({"index": 1})).unwrap(); + select("Brights"); + let steps = json!([ + {"command": "document.activate", "params": {"index": 2}}, + {"command": "swatch.renameGroup", "params": {"group": "Brights", "name": "Vivid"}}, + {"command": "document.activate", "params": {"index": 1}}, + ]); + app.run("command.batch", json!({"commands": steps})).unwrap(); + assert_eq!((selected(&ctx), pstate::(&ctx, "swatch-anchor")), (vec!["Brights".to_string()], "Brights".to_string())); +} + /// 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. diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 91e2ff3bc4..2f6fb92659 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -150,9 +150,11 @@ those rows with `layer.delete` in the document the question was asked in. `layer New swatches and colour groups: `ui.newSwatch {spot?, global?, group?}` opens the `newSwatch` dialog prefilled from the active fill or stroke (fields as in `swatchOptions` plus `group`; a gradient or pattern only takes `name`) and `ui.newColorGroup {swatches?}` opens `newColorGroup` (fields `name`, `fromArtwork`, `toGlobal`, `includeTints`, -`swatches`); `ui.dialog.confirm` runs `swatch.new` / `swatch.newGroup`. `ui.colorGroupOptions {group}` opens -`colorGroupOptions` (fields `name` and `__group`), whose `ui.dialog.confirm` runs `swatch.renameGroup`; a refused name -keeps the dialog open. +`swatches`); `ui.dialog.confirm` runs `swatch.new` / `swatch.newGroup`. `ui.colorGroupOptions {group?}` opens +`colorGroupOptions` (fields `name`, `__group`, `__swatches`, `__index` and `__doc`) for `group`, or without it for the +color group selected alone in the Swatches panel; its `ui.dialog.confirm` runs `swatch.renameGroup`. A refused name keeps +the dialog open; when another document is active, or the color group at the group's place in the list no longer has the +name and swatches it opened with, the confirm closes the dialog and renames nothing. The Color Picker is a dialog too: `engine.execute {command: "ui.colorPicker", params: {stroke?, color?}}` opens it for the fill (or stroke) proxy; `ui.dialog.set {field: "hex", value: "00FF00"}` (or `color`, `channel`, `webOnly`, `swatches`) then `ui.dialog.confirm` applies the colour through `paint.setFill` / `paint.setStroke`. diff --git a/docs/mcp.md b/docs/mcp.md index 6ea314ed19..776e14f1f0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -1103,7 +1103,7 @@ names Select All Unused selects; a spot swatch counts as used while an image pla its ink), `swatch.merge {names}` (the first is kept; gradient stops linked to the others drop their process plates), `swatch.ungroup {name}`, `swatch.renameGroup {group, name}` (Color Group Options: renames the group alone in one undo step; the name is trimmed, and a name that is empty or that another color group or a swatch has is an -error; the group's own name records no undo step) and +error; the group's own name records no undo step, and a drag still in progress becomes an undo step of its own first) and `swatch.sortByKind`. `brush.move {name | names, to?, type?}` reorders brushes among the brushes of their type, as dragging one onto another of its type in the Brushes panel does. `to` is an index among the brushes of that type in `brush.list`