From 3e67818f4ad22ec621866f83b6e3fd38d194f07d Mon Sep 17 00:00:00 2001 From: ruchirguitar <113586074+ruchirguitar@users.noreply.github.com> Date: Wed, 2 Dec 2026 08:28:41 +0530 Subject: [PATCH] Artwork Cleanup: offer actions on scan results --- crates/ui-egui/src/addons/cleanup.rs | 46 ++++++++++++++++---- crates/ui-egui/src/addons/cleanup/tests.rs | 50 ++++++++++++++++++++++ docs/target-app-parity.md | 4 +- 3 files changed, 91 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/addons/cleanup.rs b/crates/ui-egui/src/addons/cleanup.rs index 8ce1aa6812..1b012b66f7 100644 --- a/crates/ui-egui/src/addons/cleanup.rs +++ b/crates/ui-egui/src/addons/cleanup.rs @@ -8,10 +8,11 @@ use craft::behavior::{DisplayOrder, ItemSource, Selection}; use craft::keymap::Mods; use craft::menu::Node; use craft::ui::buttons::Button; -use craft::ui::contract::{Bind, Props as _, Show as _, ShowCollection as _, ShowContainer as _}; +use craft::ui::contract::{Bind, CollectionEvent, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _}; use craft::ui::display::{Divider, Text}; use craft::ui::layout_components::Row; use craft::ui::list::{List, ListRow}; +use craft::ui::menu::{Menu, MenuItem}; use craft::ui::sections::Section; use egui::Ui; use serde_json::{Value, json}; @@ -136,6 +137,8 @@ pub(crate) struct Results { rows: Vec<(String, String, u64)>, /// The rows picked in the list, by position in `rows`. picked: Selection, + /// The clicked finding and the kinds to fix, captured when its menu opens. + menu: Option<(String, Vec)>, /// What the last fix did. status: String, } @@ -320,14 +323,41 @@ fn text_tools(ui: &mut Ui, selected: bool, editing: bool, action: &mut Option) { let source = Positional { rows: &r.rows, label: |row| row.1.as_str() }; - List::::new(tl!("Issues").to_string()).empty(tl!("No issues found.").to_string()).selection(Bind::bound(&mut r.picked)).show_items( - ui, - &source, - &mut |key, _| match r.rows.get(*key) { - Some((_, label, count)) => ListRow::new(tl!(label).to_string()).trailing(count.to_string()), + let mut selection = r.picked.clone(); + let out = List::::new(tl!("Issues")) + .id(ui.scope_id().with(("cleanup-issues", r.doc))) + .select(SelectMode::Multi) + .row_menu() + .empty(tl!("No issues found.").to_string()) + .selection(Bind::bound(&mut selection)) + .show_items(ui, &source, &mut |key, item| match r.rows.get(*key) { + Some((_, label, count)) => ListRow::new(tl!(label).to_string()).trailing(count.to_string()).state(item.row.clone()), None => ListRow::spacer(), - }, - ); + }); + if let Some(key) = out.events.iter().find_map(|event| match event { + CollectionEvent::ContextMenu(request) => Some(request.key), + _ => None, + }) { + if !r.picked.items.contains(&key) { + r.picked = Selection::single(key); + } + r.menu = r.rows.get(key).map(|row| (row.0.clone(), r.picked_kinds())); + } else { + r.picked = selection; + } + if let Some((kind, kinds)) = &r.menu { + let menu = Menu::context(tl!("Issues"), &out.response).show(ui, |ui, _| { + if MenuItem::new(tl!("Show Affected Artwork")).show(ui).ran { + *action = Some(Action::Show(kind.clone())); + } + if MenuItem::new(tl!("Fix Selected")).show(ui).ran { + *action = Some(Action::Fix(kinds.clone())); + } + }); + if menu.output.closed.is_some() || action.is_some() { + r.menu = None; + } + } if !r.status.is_empty() { Text::new(r.status.clone()).show(ui); } diff --git a/crates/ui-egui/src/addons/cleanup/tests.rs b/crates/ui-egui/src/addons/cleanup/tests.rs index 1b414177fb..072eb5e8fc 100644 --- a/crates/ui-egui/src/addons/cleanup/tests.rs +++ b/crates/ui-egui/src/addons/cleanup/tests.rs @@ -3,6 +3,7 @@ use vectorcraft_engine::Session; use super::{check, current, fix}; use crate::VectorcraftApp; +use crate::tests::panel_harness::Panel; /// An app with a rectangle and a stray point (a path of one anchor), nothing selected. fn app() -> VectorcraftApp { @@ -46,3 +47,52 @@ fn a_fix_with_no_results_does_nothing() { assert!(app.addon_panels.cleanup.is_none()); assert_eq!(app.session.doc().unwrap().history.undo.len(), steps, "nothing was fixed without a check"); } + +#[test] +fn a_selected_rows_menu_shows_its_own_artwork_and_fixes_the_whole_selection() { + let mut app = app(); + let outside = app.run("shape.rectangle", json!({"x": 500, "y": 500, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("select.none", json!({})).unwrap(); + check(&mut app, None); + let mut panel = Panel::new(app, super::show); + panel.click("Off-Artboard Art"); + panel.click_with("Stray Points", egui::Modifiers::SHIFT); + panel.secondary_click("Off-Artboard Art"); + panel.click_menu_item("Show Affected Artwork"); + assert_eq!(panel.app().session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(outside)]); + panel.secondary_click("Off-Artboard Art"); + panel.click_menu_item("Fix Selected"); + assert!(current(&panel.app()).unwrap().rows.is_empty(), "both findings were fixed"); +} + +#[test] +fn opening_the_menu_on_an_unselected_row_fixes_only_that_finding() { + let mut app = app(); + app.run("shape.rectangle", json!({"x": 500, "y": 500, "width": 20, "height": 20})).unwrap(); + check(&mut app, Some("document")); + let mut panel = Panel::new(app, super::show); + panel.click("Stray Points"); + panel.secondary_click("Off-Artboard Art"); + panel.click_menu_item("Fix Selected"); + let app = panel.app(); + let remaining = ¤t(&app).unwrap().rows; + assert_eq!(remaining.len(), 1); + assert_eq!(remaining[0].0, "strayPoints"); +} + +#[test] +fn dismissing_the_keyboard_menu_returns_focus_to_the_finding() { + let mut app = app(); + check(&mut app, None); + let mut panel = Panel::new(app, super::show); + panel.focus("Stray Points"); + panel.key(egui::Key::F10, egui::Modifiers::SHIFT); + panel.frame(); + panel.frame(); + assert!(panel.focused("Show Affected Artwork")); + panel.key(egui::Key::Escape, egui::Modifiers::NONE); + panel.frame(); + panel.frame(); + assert!(panel.focused("Stray Points")); + assert!(!panel.shows("Show Affected Artwork")); +} diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index aa49d934ac..389fb7c9ae 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2978,7 +2978,9 @@ panel run `addon.cleanup.*`: Simplify Anchors (Keep Shape) on the shared kernel Show, Fix Selected and Fix All (each one undo step), Deep Ungroup and Rejoin Path Pieces. Tests: `addons::` in `vectorcraft-pathops`, `cmd::addons::cleanup::tests` in `vectorcraft-engine` (each kind found, fixed and clean art left alone; Fix All as one step; scopes; rejoin within the gap only) and `addons::cleanup::tests` in `vectorcraft-ui-egui` -(the submenu opens the panel; Check lists what it finds). Commands: `docs/mcp.md` › Artwork Cleanup add-on. +(the submenu opens the panel; Check lists what it finds). A result row's context menu shows the artwork for that +finding or fixes the selected findings. Opening the menu on a selected row keeps the other selected rows. +Commands: `docs/mcp.md` › Artwork Cleanup add-on. The add-on's text tools (2026-10-31) work on the shared text layout: Break Text into lines, paragraphs, words or glyphs and Split Text at Cursor make point type pieces placed by the glyph of their first character, Combine Point Text merges