From b026540672ee47e6c5a7841f63efbd458b98f248 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 12:13:34 -0800 Subject: [PATCH] Attributes: URL and Note fields use the shared selection target The URL and Note fields now take their edit target from panels::selection_target instead of a copy of its key in attributes.rs. The shared target also holds the selected symbol part, so selecting a part of a symbol instance drops an unfinished URL or note: attributes.set does not edit a selected part. --- crates/ui-egui/src/panels/attributes.rs | 44 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/ui-egui/src/panels/attributes.rs b/crates/ui-egui/src/panels/attributes.rs index f940a8de81..7850236147 100644 --- a/crates/ui-egui/src/panels/attributes.rs +++ b/crates/ui-egui/src/panels/attributes.rs @@ -24,7 +24,7 @@ use vectorcraft_doc::{ImageMap, NodeId, NodeKind}; use vectorcraft_engine::cmd::{AttributesInfo, RECENT_URLS}; use vectorcraft_geom::FillRule; -use super::{part_hidden, selection_len, set_part_hidden}; +use super::{part_hidden, selection_len, selection_target, set_part_hidden}; use crate::VectorcraftApp; /// The part store's key for the options (centre, direction, fill rule, image map, URL). @@ -116,20 +116,6 @@ fn info(app: &mut VectorcraftApp) -> (AttributesInfo, bool) { v } -/// What the URL and Note fields edit, as their edit target: the document, how many times File › Revert and Undo or -/// Redo replaced its content (after which a node id can name another object), and the selected objects (or the object -/// targeted in the Layers panel) in id order. A field drops an unfinished value when this changes, even where the new -/// objects hold the same text, and keeps it when the same objects are selected in another order. -type EditTarget = Option<(u64, u64, u64, Vec)>; - -/// The [`EditTarget`] of the active document. -fn edit_target(app: &VectorcraftApp) -> EditTarget { - let st = app.session.active()?; - let mut subjects = st.selection.subjects().to_vec(); - subjects.sort_unstable(); - Some((st.uid, st.reverts, st.history_restores, subjects)) -} - /// A value the targets share, or mixed where they differ (`None`). fn or_mixed(v: Option) -> Mixed { v.map_or(Mixed::Mixed, Mixed::Same) @@ -153,7 +139,8 @@ fn pair(ui: &mut Ui, name: &'static str, enabled: bool, current: Opti pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let (info, paths) = info(app); let has = !info.ids.is_empty(); - let target = edit_target(app); + // The URL and Note fields drop an unfinished value when the selection target changes. + let target = selection_target(app); // (command, params) for each edit of this pass; errors show in the status bar through `run`. let mut acts: Vec<(&'static str, Value)> = Vec::new(); Row::new().show(ui, |ui, _| { @@ -490,6 +477,31 @@ mod tests { assert_eq!((notes.0.as_deref(), notes.1.as_deref()), (Some("typed note"), Some("typed note")), "both objects take the note"); } + /// Selecting a part of a symbol instance drops an unfinished note: a selected part takes no note, so selecting the + /// instance again and clicking elsewhere leaves the instance's note. + #[test] + fn selecting_a_part_of_the_instance_drops_an_unfinished_note() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + run(&mut app, "file.new", json!({"width": 100, "height": 100})); + let left = run(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 30, "height": 30}))["id"].clone(); + let right = run(&mut app, "shape.rectangle", json!({"x": 50, "y": 0, "width": 30, "height": 30}))["id"].clone(); + let instance = run(&mut app, "symbol.new", json!({"name": "Pair", "ids": [left, right], "type": "dynamic"}))["id"].as_u64().unwrap(); + run(&mut app, "attributes.set", json!({"ids": [instance], "note": "instance note"})); + run(&mut app, "select.set", json!({"ids": [instance]})); + let mut panel = Panel::new(app, show); + panel.room(egui::vec2(320.0, 480.0)); + panel.frame(); + unfinished(&mut panel, "Note", "typed note"); + run(&mut panel.app(), "symbol.instance.selectPart", json!({"id": instance, "path": [0]})); + settle(&mut panel); + assert_ne!(panel.value("Note").as_deref(), Some("typed note"), "the Note field drops the unfinished note"); + run(&mut panel.app(), "select.set", json!({"ids": [instance]})); + settle(&mut panel); + let at = below(&panel); + panel.click_at(at); + assert_eq!(url_and_note(&panel, instance).1.as_deref(), Some("instance note"), "the instance keeps its note"); + } + /// Only web and mail URLs reach the browser. #[test] fn the_browser_opens_web_and_mail_urls_only() {