From 3e29a71b9986754961467c16f90c0ec93485d7c7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 18:05:26 -0800 Subject: [PATCH] Selection Tools: Edit Points Only keeps Appearance row changes and other status messages Replacing or canceling a drag's preview restores the Appearance row only when the preview itself changed it, so a row set or cleared during the drag stays. The dialog clears only its own preview error, and only while it is still the current status message. The group expansion test checks behavior instead of source text. --- crates/engine/src/cmd/addons/select.rs | 2 +- crates/engine/src/cmd/addons/select/tests.rs | 50 +++++++++++++++++-- crates/engine/src/cmd/appearance.rs | 17 ++++++- crates/engine/src/interaction.rs | 8 ++- crates/engine/src/session/edit.rs | 28 +++++++---- crates/ui-egui/src/addons/dialogs.rs | 25 ++++++++-- .../src/addons/select/points_only/tests.rs | 42 ++++++++++++++++ docs/mcp.md | 4 ++ 8 files changed, 154 insertions(+), 22 deletions(-) diff --git a/crates/engine/src/cmd/addons/select.rs b/crates/engine/src/cmd/addons/select.rs index fb8c49aed6..e99294a4b0 100644 --- a/crates/engine/src/cmd/addons/select.rs +++ b/crates/engine/src/cmd/addons/select.rs @@ -54,7 +54,7 @@ pub fn specs() -> Vec { "Edit Points Only", ["Object", "Plug-ins", "Selection Tools"], None, - "{segmentEnds?: false (true: the points at the ends of each selected segment stay selected, as anchor points; any non-boolean value, including null, is an error)} narrow the selection to paths and their selected anchor points: a path with selected anchor points keeps them; a path with selected segments drops the segments and keeps its other selected anchor points, and the points at the segments' ends leave the selection unless segmentEnds is true; a path selected whole stays selected whole and still receives object transforms, including stroke and effect scaling when enabled; a group or compound path selected whole gives way to the paths inside it, each selected whole unless it has an explicit anchor pick, leaving out hidden and locked ones, a Shaper Group's original shapes and, while guides are locked, paths made into guides; explicit anchor picks take precedence regardless of selection order; type, images, symbols, meshes and other objects without anchor points, and ruler guides, leave the selection. With nothing selected, or no anchor point left to keep, it is an error that leaves the selection as it was. The command does not add an undo step → {changed (false when the selection already held only anchor points), count (the paths left selected), points (the anchor points selected on them)}", + "{segmentEnds?: false (true: the points at the ends of each selected segment stay selected, as anchor points; any non-boolean value, including null, is an error)} narrow the selection to paths and their selected anchor points: a path with selected anchor points keeps them; a path with selected segments drops the segments and keeps its other selected anchor points, and the points at the segments' ends leave the selection unless segmentEnds is true; a path selected whole stays selected whole and still receives object transforms, including stroke and effect scaling when enabled; a group or compound path selected whole gives way to the paths inside it, each selected whole unless it has an explicit anchor pick, leaving out hidden and locked ones, a Shaper Group's original shapes and, while guides are locked, paths made into guides; explicit anchor picks take precedence regardless of selection order; type, images, symbols, meshes and other objects without anchor points, and ruler guides, leave the selection. With nothing selected, or no anchor point left to keep, it is an error that leaves the selection as it was. The command does not add an undo step. In the desktop dialog, a successful preview or OK clears only that dialog's preview error if it is still the current status message → {changed (false when the selection already held only anchor points), count (the paths left selected), points (the anchor points selected on them)}", has_doc, edit_points_only ), diff --git a/crates/engine/src/cmd/addons/select/tests.rs b/crates/engine/src/cmd/addons/select/tests.rs index 6171c08ef9..4b86ae5802 100644 --- a/crates/engine/src/cmd/addons/select/tests.rs +++ b/crates/engine/src/cmd/addons/select/tests.rs @@ -487,11 +487,7 @@ mod edit_points_only { } #[test] - fn group_expansion_does_not_scan_the_selection_for_each_descendant() { - let source = include_str!("../select.rs"); - let command = source.split("fn edit_points_only(").nth(1).unwrap(); - assert!(!command.contains("sel.objects.contains(&c.id)"), "descendant lookup must not scan every selected object"); - + fn group_expansion_selects_each_descendant_path() { let (mut s, _, _) = two(); let mut groups = vec![]; let mut paths = vec![]; @@ -507,6 +503,48 @@ mod edit_points_only { assert_eq!(picked(&s), (paths, BTreeMap::new())); } + #[test] + fn appearance_row_commands_survive_preview_replacement_and_cancel() { + for index in [json!(1), Value::Null] { + for selection_preview in [false, true] { + let (mut s, a, b) = two(); + mixed(&mut s, a, b); + s.execute("appearance.addFill", &json!({})).unwrap(); + s.execute("appearance.setActiveItem", &json!({"index": 0})).unwrap(); + s.begin_interaction("Drag").unwrap(); + s.doc_mut().unwrap().interaction.as_mut().unwrap().tool = !selection_preview; + if selection_preview { + s.preview(C, &json!({})).unwrap(); + assert_eq!(s.appearance_item(), None); + } else { + s.preview("object.move", &json!({"dx": 10, "dy": 0})).unwrap(); + } + s.execute("appearance.setActiveItem", &json!({"index": index})).unwrap(); + let expected = index.as_u64().map(|i| i as usize); + s.preview("object.move", &json!({"dx": 20, "dy": 0})).unwrap(); + assert_eq!(s.appearance_item(), expected, "replacement preserves the explicit row command"); + s.cancel_interaction().unwrap(); + assert_eq!(s.appearance_item(), expected, "cancel preserves the explicit row command"); + } + } + } + + #[test] + fn cancel_preserves_an_appearance_row_command_without_another_preview() { + for index in [json!(1), Value::Null] { + let (mut s, a, b) = two(); + mixed(&mut s, a, b); + s.execute("appearance.addFill", &json!({})).unwrap(); + s.execute("appearance.setActiveItem", &json!({"index": 0})).unwrap(); + s.begin_interaction("Drag").unwrap(); + s.doc_mut().unwrap().interaction.as_mut().unwrap().tool = true; + s.preview(C, &json!({})).unwrap(); + s.execute("appearance.setActiveItem", &json!({"index": index})).unwrap(); + s.cancel_interaction().unwrap(); + assert_eq!(s.appearance_item(), index.as_u64().map(|i| i as usize)); + } + } + #[test] fn canceling_a_selection_preview_restores_the_active_appearance_item() { let (mut s, a, b) = two(); @@ -517,6 +555,8 @@ mod edit_points_only { s.begin_interaction("Edit Points Only").unwrap(); s.preview(C, &json!({})).unwrap(); assert_eq!(s.appearance_item(), None); + s.preview(C, &json!({"segmentEnds": true})).unwrap(); + assert_eq!(s.appearance_item(), None); s.cancel_interaction().unwrap(); assert_eq!(s.appearance_item(), Some(0)); s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap(); diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index d319e0d2a4..a530efce99 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -139,7 +139,7 @@ pub fn specs() -> Vec { "Select Appearance Item", [], None, - "{index: paint-order item index in the first selected object's stack | null} make that fill/stroke row the target of the paint.setFill/setStroke, stroke.set/setAdvanced, paint.editGradient/setGradientGeom, transparency.set and effect.* calls that omit `item` (a fill row brings the Fill proxy forward, a stroke row the Stroke proxy); null or any selection change clears it → {index}", + "{index: paint-order item index in the first selected object's stack | null} make that fill/stroke row the target of the paint.setFill/setStroke, stroke.set/setAdvanced, paint.editGradient/setGradientGeom, transparency.set and effect.* calls that omit `item` (a fill row brings the Fill proxy forward, a stroke row the Stroke proxy); null or any selection change clears it. A row set or cleared outside a drag's preview stays set or cleared when the preview is replaced or canceled → {index}", has_selection, set_active_item ), @@ -174,7 +174,7 @@ pub fn specs() -> Vec { } /// The Appearance panel's active row, remembered for the selection it was chosen in. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq)] pub(crate) struct ActiveItem { doc: u64, objects: Vec, @@ -956,6 +956,7 @@ fn set_active_item(s: &mut Session, p: &Value) -> Result { let index = match p.get("index") { Some(Value::Null) => { s.active_appearance_item = None; + clear_preview_item(s); return Ok(json!({ "index": Value::Null })); } Some(_) => index_param(p, "index", C)?, @@ -968,9 +969,21 @@ fn set_active_item(s: &mut Session, p: &Value) -> Result { let doc = st.uid; s.fill_active = fill; s.active_appearance_item = Some(ActiveItem { doc, objects, index }); + clear_preview_item(s); Ok(json!({ "index": index })) } +fn clear_preview_item(s: &mut Session) { + if !s.previewing { + if let Some(it) = s.active_mut().and_then(|st| st.interaction.as_mut()) { + it.active_appearance_item = None; + } + if let Some(held) = &mut s.held_interaction { + held.interaction.active_appearance_item = None; + } + } +} + fn add_item(s: &mut Session, p: &Value, fill: bool) -> Result { let cmd = if fill { "appearance.addFill" } else { "appearance.addStroke" }; let mut ids = row_targets(s, p, cmd)?; diff --git a/crates/engine/src/interaction.rs b/crates/engine/src/interaction.rs index dc7b5684fe..748dd764cc 100644 --- a/crates/engine/src/interaction.rs +++ b/crates/engine/src/interaction.rs @@ -10,7 +10,7 @@ pub struct Interaction { pub doc: Arc, /// The selection the previews start from (shared, so a preview frame copies nothing). pub selection: Arc, - pub(crate) active_appearance_item: Option, + pub(crate) active_appearance_item: Option, pub preview: Option<(String, Value)>, /// The active tool began it (a drag): a command from outside the tool runs as a step of its /// own under it ([`crate::Session::outside_interaction`]). A dialog or a panel that begins an @@ -53,6 +53,12 @@ pub struct Interaction { pub keep_on_switch: bool, } +#[derive(Clone, Debug)] +pub(crate) struct PreviewAppearanceItem { + pub(crate) before: Option, + pub(crate) after: Option, +} + /// An interaction that a command from outside the tool set aside while it runs /// ([`crate::Session::outside_interaction`]). #[derive(Debug)] diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index 45d0dfd370..e337be95ab 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -536,7 +536,6 @@ impl Session { } self.clear_deferred_overlay_cache(); let paint = self.paint.clone(); - let active_appearance_item = self.active_appearance_item.clone(); let st = self.doc_mut()?; if st.interaction.is_some() { return Ok(()); @@ -546,7 +545,7 @@ impl Session { effect: None, doc: st.doc.clone(), selection: Arc::new(st.selection.clone()), - active_appearance_item, + active_appearance_item: None, preview: None, tool: false, paint, @@ -574,12 +573,14 @@ impl Session { if self.script_running() { return Err(EngineError::Busy); } + self.restore_preview_appearance_item(); + let before_item = self.active_appearance_item.clone(); // While the active tool paints with the chosen fill or stroke (the Live Paint Bucket, the // Shape Builder), paint previews of that kind change only the colors it paints with, so each // preview starts from the colors the interaction began with; so does a preview with // `defaultsOnly: true`, and one after it. let tool_paints = self.tool_paints(false) || self.tool_paints(true); - let (paint, restore_paint, active_appearance_item) = { + let (paint, restore_paint) = { let menu = self.menu.clone(); let st = self.doc_mut()?; let Some(it) = &mut st.interaction else { return Err(EngineError::Other("no interaction in progress".into())) }; @@ -601,7 +602,6 @@ impl Session { || it.preview.as_ref().is_some_and(|(id, p)| id == "command.batch" || cmd::asks_defaults_only(p)) || it.color_mode_paints.is_some(); let paint = it.paint.clone(); - let active_appearance_item = it.active_appearance_item.clone(); it.preview_paint = None; it.color_mode_paints = None; it.deferred_color_mode = None; @@ -618,9 +618,8 @@ impl Session { // undone with it. st.restore_isolation(isolation, &undone); cmd::globaledit::follow_history(st); - (paint, restore_paint, active_appearance_item) + (paint, restore_paint) }; - self.active_appearance_item = active_appearance_item; if restore_paint { self.paint = paint.clone(); } @@ -642,8 +641,11 @@ impl Session { } let params = self.noted(params); let batch_paint = (r.is_ok() && cmd == "command.batch").then(|| self.paint.clone()); + let after_item = self.active_appearance_item.clone(); let st = self.doc_mut()?; if let Some(it) = &mut st.interaction { + it.active_appearance_item = + (before_item != after_item).then_some(crate::interaction::PreviewAppearanceItem { before: before_item, after: after_item }); it.used_defaults_only |= ran_defaults_only; // A failed preview leaves the document at the snapshot, so nothing is left to commit // (not even an earlier successful preview, which the reset above already undid). @@ -761,8 +763,18 @@ impl Session { } } + fn restore_preview_appearance_item(&mut self) { + let changed = self.active_mut().and_then(|st| st.interaction.as_mut()).and_then(|it| it.active_appearance_item.take()); + if let Some(changed) = changed + && self.active_appearance_item == changed.after + { + self.active_appearance_item = changed.before; + } + } + pub fn cancel_interaction(&mut self) -> Result<()> { self.put_back_interaction(); + self.restore_preview_appearance_item(); self.clear_deferred_overlay_cache(); self.decoded_images.empty(); self.pending_paint = None; @@ -786,14 +798,10 @@ impl Session { self.paint = paint; } let menu = self.menu.clone(); - let active_appearance_item = self.active().and_then(|st| st.interaction.as_ref()).map(|it| it.active_appearance_item.clone()); let st = self.doc_mut()?; st.undo_interaction(); // Guides locked and slices locked or hidden during the interaction stay deselected. deselect_hidden(&menu, &st.doc, &mut st.selection); - if let Some(active_appearance_item) = active_appearance_item { - self.active_appearance_item = active_appearance_item; - } // A canceled preview's Assign Profile is undone with it. self.sync_front_profiles(); // With New Art Has Basic Appearance off, new art takes the appearance of the selection as diff --git a/crates/ui-egui/src/addons/dialogs.rs b/crates/ui-egui/src/addons/dialogs.rs index f0642c31fc..a1c9dcf5b8 100644 --- a/crates/ui-egui/src/addons/dialogs.rs +++ b/crates/ui-egui/src/addons/dialogs.rs @@ -34,6 +34,7 @@ pub(crate) struct Spec { pub(crate) struct AddonDialogs { open: Option, preview: LivePreview, + preview_error: Option<(u64, String)>, /// The open Tangent Circle Tool radius dialog. pub(crate) tangent_radius: Option, } @@ -65,6 +66,7 @@ fn active_document(app: &VectorcraftApp) -> Option<(u64, u64)> { /// Closes the open add-on dialog without an answer and rolls its preview back. fn close_open(app: &mut VectorcraftApp) { let Some(open) = app.addon_dialogs.open.take() else { return }; + app.addon_dialogs.preview_error = None; let id = open.id; if let (Some(host), Some(ctx)) = (app.dialogs(), app.ui_ctx.clone()) { host.with(|h| { @@ -133,6 +135,7 @@ fn pump_commit(app: &mut VectorcraftApp) { if !on_document { // Switching drawings already ends the old preview. Discard its bookkeeping without touching the other drawing. app.addon_dialogs.preview = LivePreview::default(); + app.addon_dialogs.preview_error = None; } let live = host.with(|h| h.get_mut_by_id::(id).map(|d| (d.is_previewing(), (spec.params)(d.fields())))); if on_document && let Some((previewing, params)) = &live { @@ -140,8 +143,12 @@ fn pump_commit(app: &mut VectorcraftApp) { let label = vectorcraft_engine::find_command(spec.command).map_or(spec.command, |command| command.label); let answer = preview.run(app, *previewing, label, spec.command, params); app.addon_dialogs.preview = preview; - if spec.command == super::select::points_only::COMMAND && matches!(&answer, Some(Ok(_))) { - app.ui.status.clear(); + if spec.command == super::select::points_only::COMMAND { + match &answer { + Some(Err(_)) => app.addon_dialogs.preview_error = Some((app.ui.status_sets, app.ui.status.clone())), + Some(Ok(_)) => clear_preview_error(app), + None => {} + } } if let (Some(found), Some(answer)) = (spec.found, answer) { host.with(|h| { @@ -170,18 +177,30 @@ fn pump_commit(app: &mut VectorcraftApp) { if let Err(error) = answer { app.status(error); } else if spec.command == super::select::points_only::COMMAND { - app.ui.status.clear(); + clear_preview_error(app); } } + app.addon_dialogs.preview_error = None; } Some(None) => { app.addon_dialogs.open = None; + app.addon_dialogs.preview_error = None; mem::take(&mut app.addon_dialogs.preview).cancel(app); } None if live.is_none() => { app.addon_dialogs.open = None; + app.addon_dialogs.preview_error = None; mem::take(&mut app.addon_dialogs.preview).cancel(app); } None => {} } } + +fn clear_preview_error(app: &mut VectorcraftApp) { + if let Some((sets, error)) = app.addon_dialogs.preview_error.take() + && app.ui.status_sets == sets + && app.ui.status == error + { + app.ui.status.clear(); + } +} diff --git a/crates/ui-egui/src/addons/select/points_only/tests.rs b/crates/ui-egui/src/addons/select/points_only/tests.rs index ff0fef879f..75ddaf5703 100644 --- a/crates/ui-egui/src/addons/select/points_only/tests.rs +++ b/crates/ui-egui/src/addons/select/points_only/tests.rs @@ -96,6 +96,48 @@ fn cancel_puts_the_selection_back() { assert_eq!(app.session.doc().unwrap().selection, before); } +#[test] +fn successful_preview_and_confirmation_preserve_another_status() { + for previewing in [true, false] { + let (mut app, _, _) = app(); + host::open_item(&mut app, "Selection Tools", "Edit Points Only…"); + let id = host::dialog_id(&app); + app.status("The active text edit reported a warning."); + if previewing { + host::frame(&mut app); + assert_eq!(app.ui.status, "The active text edit reported a warning."); + } + assert!(host::confirm(&app, id)); + host::frame(&mut app); + assert_eq!(app.ui.status, "The active text edit reported a warning."); + assert!(!app.any_dialog_open()); + } +} + +#[test] +fn recovering_from_a_preview_error_preserves_a_later_status() { + for previewing in [true, false] { + for same_text in [true, false] { + let (mut app, a, _) = app(); + app.run("select.segments", json!({"id": a.0, "segments": [[0, 0]]})).unwrap(); + host::open_item(&mut app, "Selection Tools", "Edit Points Only…"); + let id = host::dialog_id(&app); + host::frame(&mut app); + assert!(app.ui.status.contains("no anchor points are selected")); + let status = if same_text { app.ui.status.clone() } else { "Another command reported a warning.".to_owned() }; + app.status(status.clone()); + host::set(&app, id, "segmentEnds", json!(true)); + if previewing { + host::frame(&mut app); + assert_eq!(app.ui.status, status); + } + assert!(host::confirm(&app, id)); + host::frame(&mut app); + assert_eq!(app.ui.status, status); + } + } +} + #[test] fn keeping_segment_ends_clears_the_preview_error() { for previewing in [true, false] { diff --git a/docs/mcp.md b/docs/mcp.md index 65c28a7c38..c6a4aff22a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -985,6 +985,8 @@ Cmd+Alt+/ runs `appearance.addStroke` (`press_key {key: "/", mods: {cmd: true, a `item` to edit one of them; `run_command appearance.setActiveItem {"index": n}` makes that row the target of later calls that omit `item` (as clicking the row in the Appearance panel does) until the selection changes; the proxy of its kind (`paint.proxies`) and the Gradient tool's annotator then show that row. +An `appearance.setActiveItem` call made outside a drag's preview keeps its selected row, including an explicit +`index: null`, when the preview is replaced or canceled. `inspect_document` reports it as `paint.appearanceItem`. `paint.setFill` and `paint.setStroke` also take `opacity` (0 to 100, a percentage as in `transparency.set`), which sets the opacity of the fill or stroke row they paint, with or without a new paint, as one undo step. An opacity that no target takes is an error and also leaves the paint @@ -17335,6 +17337,8 @@ anchor points selected on them. Nothing selected, no anchor point left to keep ( In the desktop app, Object › Plug-ins › Selection Tools › Edit Points Only… opens a dialog with Keep Ends of Selected Segments (off). With Preview on, the canvas shows the narrowed selection; OK keeps it and Cancel puts the selection back. +After a failed preview, a successful preview or OK clears the dialog's error only if that error is still the current +status message. Messages from other commands stay displayed. ### Vector Halftone (live)