From a0f140310d198e6546b0773df7da30f8bf26bed7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 20:05:23 -0800 Subject: [PATCH 01/48] Identify browser Place sources independently of duplicate filenames --- crates/tools/src/place.rs | 28 ++++++++- crates/ui-egui/src/place.rs | 36 ++++++++---- crates/ui-egui/src/tests/place.rs | 97 ++++++++++++++++++++++++++++++- docs/mcp.md | 5 +- 4 files changed, 148 insertions(+), 18 deletions(-) diff --git a/crates/tools/src/place.rs b/crates/tools/src/place.rs index 813ec99429..3564bb3667 100644 --- a/crates/tools/src/place.rs +++ b/crates/tools/src/place.rs @@ -12,6 +12,8 @@ use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, Tool, Tool /// One loaded file. #[derive(Clone, Debug, PartialEq)] struct Entry { + /// Its position in the original load, retained when other entries are discarded. + source_index: usize, /// `file.place` params (the file and its options). params: Value, name: String, @@ -141,12 +143,13 @@ impl Tool for PlaceTool { Cursor::Crosshair } - /// `{count, current, name, width, height, names}`: what the cursor holds (no file data). + /// `{count, current, sourceIndex, name, width, height, names}`: what the cursor holds (no file data). fn options(&self) -> Value { let e = self.entry(); json!({ "count": self.entries.len(), "current": self.current, + "sourceIndex": e.map(|e| e.source_index), "name": e.map(|e| &e.name), "width": e.map(|e| e.width), "height": e.map(|e| e.height), @@ -163,8 +166,10 @@ impl Tool for PlaceTool { .as_array() .into_iter() .flatten() - .filter_map(|e| { + .enumerate() + .filter_map(|(source_index, e)| { Some(Entry { + source_index, params: e.get("params").filter(|p| p.is_object())?.clone(), name: e["name"].as_str().unwrap_or_default().to_string(), width: e["width"].as_f64().filter(|v| v.is_finite())?, @@ -359,4 +364,23 @@ mod tests { t.key(&c, ToolKey::Escape, Mods::default()); assert_eq!(t.key(&c, ToolKey::Escape, Mods::default()), vec![Action::SwitchTool("pen".into())]); } + + #[test] + fn source_indices_survive_removal_and_never_enter_place_params() { + let (d, _) = doc_with_rect(); + let (s, p) = (Default::default(), paint()); + let c = cx(&d, &s, &p); + let mut t = loaded(3); + t.key(&c, ToolKey::Right, Mods::default()); + assert_eq!(t.options()["sourceIndex"], 1); + t.key(&c, ToolKey::Escape, Mods::default()); + assert_eq!((t.options()["current"].clone(), t.options()["sourceIndex"].clone()), (json!(1), json!(2))); + t.pointer(&c, &ev(PointerKind::Down, 0.0, 0.0)); + let acts = t.pointer(&c, &ev(PointerKind::Up, 0.0, 0.0)); + assert_eq!(acts, vec![Action::Exec("file.place".into(), json!({"path": "f2.png", "rect": [0.0, 0.0, 40.0, 20.0]}))]); + assert_eq!(t.options()["sourceIndex"], 0); + assert!(t.check_option("sourceIndex", &json!(0)).is_err(), "the source identity is read only"); + t.key(&c, ToolKey::Escape, Mods::default()); + assert_eq!(t.options()["sourceIndex"], Value::Null); + } } diff --git a/crates/ui-egui/src/place.rs b/crates/ui-egui/src/place.rs index 478cc4157d..30851eaa74 100644 --- a/crates/ui-egui/src/place.rs +++ b/crates/ui-egui/src/place.rs @@ -85,7 +85,7 @@ pub fn is_document(name: &str) -> bool { /// The app's Place state (not saved with the preferences). #[derive(Default)] pub struct PlaceState { - /// Web: the bytes of the files picked for the Place dialog, by name. + /// Web: the bytes of the files picked for the Place dialog, by selection token. pub(crate) picked: Vec<(String, Vec)>, /// The loaded cursor's thumbnails by file name. thumbs: Vec<(String, Thumb)>, @@ -140,6 +140,7 @@ const SET_ASIDE: &str = "__placeCursorOptions"; /// A place cursor thumbnail, decoded when the cursor is loaded. struct Thumb { + source_index: usize, image: std::sync::Arc, } @@ -175,6 +176,13 @@ impl PlaceState { pub(crate) fn thumbnails(&self) -> Vec<&str> { self.thumbs.iter().map(|(n, _)| n.as_str()).collect() } + + /// The current entry's thumbnail, even after earlier entries with the same name are removed. + pub(crate) fn cursor_thumbnail(&self, options: &Value) -> Option<(usize, &egui::ColorImage)> { + let source_index = usize::try_from(options["sourceIndex"].as_u64()?).ok()?; + let (_, thumb) = self.thumbs.iter().find(|(_, thumb)| thumb.source_index == source_index)?; + Some((source_index, thumb.image.as_ref())) + } } /// Run engine command `id` itself (past the UI's handling of the same id); an error shows in the @@ -346,14 +354,15 @@ fn pick(app: &mut VectorcraftApp, p: &Value) -> Value { paths.into_iter().map(|path| with_importer(json!({ "path": path.to_string_lossy() }), &with)).collect() } Picked::Contents(files) => { - // The next Place dialog replaces the previous selection, including its source bytes. + // A replacement selection owns a new set of source bytes. app.place.picked.clear(); files .into_iter() .map(|(name, bytes)| { - app.place.picked.retain(|(n, _)| *n != name); - let entry = with_importer(json!({ "name": name }), &with); - app.place.picked.push((name, bytes)); + static SOURCE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1); + let source = SOURCE.fetch_add(1, std::sync::atomic::Ordering::Relaxed).to_string(); + let entry = with_importer(json!({ "name": name, "__pickedSource": source }), &with); + app.place.picked.push((source, bytes)); entry }) .collect() @@ -476,7 +485,9 @@ fn source(app: &VectorcraftApp, file: &Value) -> Option { return Some(with_importer(json!({ "path": path }), file)); } let name = file.get("name").and_then(Value::as_str)?; - let bytes = app.place.picked.iter().find(|(n, _)| n == name).map(|(_, b)| b)?; + // The selection token is UI bookkeeping; only the original name and bytes reach the engine. + let source = file.get("__pickedSource").and_then(Value::as_str).unwrap_or(name); + let bytes = app.place.picked.iter().find(|(n, _)| n == source).map(|(_, b)| b)?; Some(with_importer(json!({ "name": name, "dataBase64": vectorcraft_format::base64_encode(bytes) }), file)) } @@ -771,11 +782,12 @@ pub(crate) fn show_thumbnails(app: &mut VectorcraftApp, r: &Value, asks: bool) { .as_array() .into_iter() .flatten() - .filter_map(|f| { + .enumerate() + .filter_map(|(source_index, f)| { let png = vectorcraft_format::base64_decode(f["thumbnailBase64"].as_str()?)?; let img = craft_image_codecs::decode_as(craft_image_codecs::Format::Png, &png).ok()?; let color = egui::ColorImage::from_rgba_unmultiplied([img.width() as usize, img.height() as usize], &img.to_rgba8()); - Some((f["name"].as_str()?.to_string(), Thumb { image: std::sync::Arc::new(color) })) + Some((f["name"].as_str()?.to_string(), Thumb { source_index, image: std::sync::Arc::new(color) })) }) .collect(); } @@ -787,15 +799,15 @@ pub fn cursor_overlay(app: &mut VectorcraftApp, ui: &mut egui::Ui, at: egui::Pos let opts = app.session.tool_options(); let count = opts["count"].as_u64().unwrap_or(0); let name = opts["name"].as_str().unwrap_or_default(); - let found = app.place.thumbs.iter().enumerate().find(|(_, (n, _))| n == name); + let found = (app.place.queue_load == app.session.place_queue_loads()).then(|| app.place.cursor_thumbnail(&opts)).flatten(); let revision = Revision::new(app.place.queue_load); let room = egui::Rect::from_min_max(at, ui.max_rect().max.max(at)); ui.scope_builder(egui::UiBuilder::new().max_rect(room), |ui| { match found { - Some((key, (_, thumb))) => { + Some((key, image)) => { let side = |n: usize| u16::try_from(n.max(1)).unwrap_or(u16::MAX); - let [w, h] = thumb.image.size; - Picture::new(name.to_string(), key as u64, &|| (*thumb.image).clone()) + let [w, h] = image.size; + Picture::new(name.to_string(), key as u64, &|| image.clone()) .revision(revision) .aspect(ThumbAspect::new(side(w), side(h))) .extent(PictureSize::Thumb(ThumbSize::Medium)) diff --git a/crates/ui-egui/src/tests/place.rs b/crates/ui-egui/src/tests/place.rs index 5aad0ffa32..52faf0b85e 100644 --- a/crates/ui-egui/src/tests/place.rs +++ b/crates/ui-egui/src/tests/place.rs @@ -134,11 +134,12 @@ fn cancelling_browser_place_releases_the_picked_file_buffers() { crate::file_asks::poll(&mut app); assert_eq!(dialog_kind(&app).as_deref(), Some(crate::dialogs::place::KIND)); assert_eq!(app.place.picked.len(), 1); + let source = app.place.picked[0].0.clone(); // Cancelling a replacement file picker leaves the existing Place selection usable. app.run("file.place", json!({})).unwrap(); picker.cancel(); crate::file_asks::poll(&mut app); - assert_eq!(app.place.picked[0].0, name); + assert_eq!(app.place.picked[0].0, source); dismiss(&mut app); crate::place::pump(&mut app, &ctx); assert!(app.place.picked.is_empty(), "a cancelled Place selection no longer owns file bytes"); @@ -210,7 +211,7 @@ fn an_old_place_ok_cannot_consume_a_newer_dialogs_browser_bytes() { assert_eq!(app.ui.status, "new selection", "the retired OK reports no stale error"); assert_eq!(dialog_kind(&app).as_deref(), Some(crate::dialogs::place::KIND)); assert_eq!(app.place.picked.len(), 1); - assert_eq!(app.place.picked[0].0, "new.png"); + assert_eq!(app.place.picked[0].1.as_slice(), bytes.as_slice()); assert!(app.session.active().unwrap().doc.layers[0].children().unwrap().is_empty()); answer(&mut app, &[("link", json!(false)), ("showImportOptions", json!(false))]); assert!(app.place.picked.is_empty()); @@ -234,7 +235,7 @@ fn an_old_place_cancellation_keeps_a_newer_dialogs_browser_bytes() { crate::place::pump(&mut app, &ctx); assert_eq!(dialog_kind(&app).as_deref(), Some(crate::dialogs::place::KIND)); assert_eq!(app.place.picked.len(), 1, "the replacement owns only its own source bytes"); - assert_eq!(app.place.picked[0].0, "new.png"); + assert_eq!(app.place.picked[0].1.as_slice(), bytes.as_slice()); answer(&mut app, &[("link", json!(false)), ("showImportOptions", json!(false))]); assert!(app.place.picked.is_empty(), "confirmation transfers the bytes out of the dialog cache"); assert_eq!(app.session.active().unwrap().doc.layers[0].children().unwrap().len(), 1, "the newer file still places"); @@ -323,6 +324,96 @@ fn selected_image(app: &VectorcraftApp) -> vectorcraft_doc::Node { n } +/// Browser file names are labels, not unique source identities. Both the bytes and the cursor +/// thumbnail must follow each selection through cycling, placement and discarding another file. +#[test] +fn browser_place_keeps_same_named_files_and_their_cursor_thumbnails_distinct() { + let mut app = app(); + let ctx = window(&app); + let picker = scripted(&mut app); + let (a, b) = (png(8, 5, 72.0), png(3, 2, 72.0)); + let load = |app: &mut VectorcraftApp| { + app.run("file.place", json!({})).unwrap(); + picker.answer_contents(&[("same.png", &a), ("same.png", &b)]); + poll(app, &ctx); + assert_eq!( + fields(app)["files"].as_array().unwrap().iter().map(|f| f["name"].as_str().unwrap()).collect::>(), + ["same.png", "same.png"] + ); + answer(app, &[("link", json!(false)), ("showImportOptions", json!(false))]); + assert_eq!(app.session.tool_options()["count"], 2); + }; + let thumbnail = |app: &VectorcraftApp| { + let options = app.session.tool_options(); + let (source, image) = app.place.cursor_thumbnail(&options).expect("the selected entry has its own thumbnail"); + (source, image.size) + }; + let placed = |app: &VectorcraftApp, size| { + let node = selected_image(app); + assert_eq!(node.name.as_deref(), Some("same.png")); + let NodeKind::Image(image) = node.kind else { panic!("Place selects the raster just placed") }; + assert_eq!((image.width, image.height), size); + }; + load(&mut app); + let first = thumbnail(&app); + tool_key(&mut app, vectorcraft_tools::ToolKey::Right); + let second = thumbnail(&app); + assert_eq!((first.0, second.0), (0, 1)); + assert_ne!(first.1, second.1, "the distinct image proportions have distinct thumbnails"); + tool_key(&mut app, vectorcraft_tools::ToolKey::Left); + click(&mut app); + placed(&app, (8, 5)); + assert_eq!(thumbnail(&app), second, "removing the first entry must not shift the thumbnail identity"); + click(&mut app); + placed(&app, (3, 2)); + + load(&mut app); + tool_key(&mut app, vectorcraft_tools::ToolKey::Escape); + assert_eq!(thumbnail(&app), second, "discarding the first entry preserves the second thumbnail"); + click(&mut app); + placed(&app, (3, 2)); +} + +/// Each browser selection places its own bytes, in selection order, with its original name. +#[test] +fn browser_place_keeps_same_named_file_bytes_in_order() { + let mut app = app(); + let ctx = window(&app); + let picker = scripted(&mut app); + let (a, b) = (png(8, 5, 72.0), png(3, 2, 72.0)); + app.run("file.place", json!({})).unwrap(); + picker.answer_contents(&[("same.png", &a), ("same.png", &b)]); + poll(&mut app, &ctx); + answer(&mut app, &[("link", json!(false)), ("showImportOptions", json!(false))]); + for size in [(8, 5), (3, 2)] { + click(&mut app); + let node = selected_image(&app); + assert_eq!(node.name.as_deref(), Some("same.png")); + let NodeKind::Image(image) = node.kind else { panic!("Place selects the raster just placed") }; + assert_eq!((image.width, image.height), size); + } +} + +/// Automation already supplies each file's bytes directly; the same names retain their order too. +#[test] +fn an_automated_place_queue_keeps_same_named_file_bytes_in_order() { + let mut app = app(); + let (a, b) = (png(8, 5, 72.0), png(3, 2, 72.0)); + app.run( + "file.place.queue", + json!({"link": false, "files": [ + {"name": "same.png", "dataBase64": vectorcraft_format::base64_encode(&a)}, + {"name": "same.png", "dataBase64": vectorcraft_format::base64_encode(&b)} + ]}), + ) + .unwrap(); + for size in [(8, 5), (3, 2)] { + click(&mut app); + let NodeKind::Image(image) = selected_image(&app).kind else { panic!("Place selects the raster just placed") }; + assert_eq!((image.width, image.height), size); + } +} + /// A tiny SVG document. const SVG: &str = r#""#; diff --git a/docs/mcp.md b/docs/mcp.md index 151708f897..d219517ee5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9840,7 +9840,10 @@ its allocation limit. Importing individual layers with `layers: true` retains it `file.place.info` describes a file without placing it and `image.info` reports a placed image's link, colour mode and effective ppi. `file.place.queue` loads the place cursor (the `place` tool) with several files: headless, drive it with `pointer_gesture` (a click places at 100% with the top-left corner there, a drag at the dragged size) and -`press_key` (Left/Right/Up/Down cycle, Escape discards the current file). The cursor keeps an encrypted PDF, `.ai` +`press_key` (Left/Right/Up/Down cycle, Escape discards the current file). The place tool's state includes a +read-only `sourceIndex`: the current file's zero-based position in the original load, or null when empty. +It stays with that file when other files are placed or discarded; `current` indexes the remaining files. +The cursor keeps an encrypted PDF, `.ai` or `.ait` file that it cannot read without the password, at 612 × 792 pt (VectorCraft's own size) with `needsPassword: true` and no thumbnail; in the app a click or drag on it asks for the password, and headless it places nothing. `file.place`, `file.place.queue` and From 1513db4d8c33a9409e23f36f89de69110c00104e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 21:27:28 -0800 Subject: [PATCH 02/48] Keep Average path approvals with their opening drawing --- crates/ui-egui/src/dialogs/path_ops.rs | 89 +++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/path_ops.rs b/crates/ui-egui/src/dialogs/path_ops.rs index 65179c95ca..d246535baa 100644 --- a/crates/ui-egui/src/dialogs/path_ops.rs +++ b/crates/ui-egui/src/dialogs/path_ops.rs @@ -426,7 +426,8 @@ fn open_dialog(app: &mut VectorcraftApp, op: PathOp, fields: DialogFields, remem app.status("There is no window to show the dialog in."); return; }; - let document = app.session.active().map(|state| state.uid); + let drawing = app.session.active().map(|state| (state.uid, state.reverts)); + let document = drawing.map(|(uid, _)| uid); if op.previews() && document.is_none() { app.status("Open a document before editing paths."); return; @@ -450,6 +451,9 @@ fn open_dialog(app: &mut VectorcraftApp, op: PathOp, fields: DialogFields, remem let Some(mut record) = take_open(app, op) else { return Err(tl!("The path dialog is closed.").to_owned()) }; record.commit(app, cmd, params).inspect_err(|_| app.object_dialogs.path.push(record))?; } else { + if app.session.active().map(|state| (state.uid, state.reverts)) != drawing { + return Err(tl!("Return to the opening drawing, or reopen this dialog after File Revert.").to_owned()); + } app.run(cmd, params).map(drop)?; } match op { @@ -616,6 +620,89 @@ pub(crate) fn original_paths(app: &VectorcraftApp) -> Vec<(NodeId, &PathData)> { .collect() } +#[cfg(test)] +mod average_document_tests { + use super::*; + use crate::dialogs::tests::{app, cancel, confirm, is_open, set}; + + fn lines(app: &mut VectorcraftApp, top: i32) -> [u64; 2] { + let a = app.run("shape.line", json!({"x1": 10, "y1": top, "x2": 50, "y2": top})).unwrap()["id"].as_u64().unwrap(); + let b = app.run("shape.line", json!({"x1": 60, "y1": top + 20, "x2": 100, "y2": top + 20})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + [a, b] + } + + fn opening_owns_approval(op: PathOp) { + for revert in [false, true] { + let mut app = app(); + let source_paths = lines(&mut app, 20); + let uid = app.session.active().unwrap().uid; + let generation = app.session.active().unwrap().reverts; + let dir = vectorcraft_testkit::TempDir::new("average-path-dialog-drawing"); + if revert { + let path = dir.join("saved-paths.vectorcraft"); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string()))); + app.run("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap(); + app.run("object.move", json!({"ids": source_paths, "dx": 12, "dy": 0})).unwrap(); + } else { + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + assert_eq!(lines(&mut app, 80), source_paths); + app.run("document.activate", json!({"index": 0})).unwrap(); + } + let open = |app: &mut VectorcraftApp| { + crate::menus::invoke(app, op.key(), json!({})); + assert!(is_open(app)); + if op == PathOp::Average { + set(app, "axis", json!("both")); + } else { + set(app, "to", json!("smooth")); + } + }; + open(&mut app); + if revert { + app.run("file.revert", json!({"confirmed": true})).unwrap(); + app.run("select.set", json!({"ids": source_paths})).unwrap(); + let restored = app.session.active().unwrap(); + assert_eq!((restored.uid, restored.reverts), (uid, generation + 1)); + } else { + app.run("document.activate", json!({"index": 1})).unwrap(); + assert_ne!(app.session.active().unwrap().uid, uid); + } + let wrong = app.session.active().unwrap(); + let (before, undo) = (wrong.doc.clone(), wrong.history.undo.len()); + let accepted = confirm(&mut app); + let after = app.session.active().unwrap(); + assert!(after.doc == before, "the old path approval must leave the other drawing contents intact"); + assert_eq!(after.history.undo.len(), undo); + assert!(!accepted && is_open(&app)); + + if revert { + assert!(cancel(&mut app)); + open(&mut app); + } else { + app.run("document.activate", json!({"index": 0})).unwrap(); + } + let before = app.session.active().unwrap(); + let (geometry, undo) = (before.doc.clone(), before.history.undo.len()); + assert!(confirm(&mut app)); + let after = app.session.active().unwrap(); + assert!(after.doc != geometry, "a current approval edits the intended paths"); + assert_eq!(after.history.undo.len(), undo + 1); + } + } + + #[test] + fn average_path_approval_stays_with_its_drawing() { + opening_owns_approval(PathOp::Average); + } + + #[test] + fn average_join_approval_stays_with_its_drawing() { + opening_owns_approval(PathOp::AverageJoin); + } +} + #[cfg(test)] mod split_tests { use serde_json::json; From f12a8f6ffe846f18aee8488b49a79c864695d076 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 21:44:59 -0800 Subject: [PATCH 03/48] Retire path options after File Revert --- crates/ui-egui/src/dialogs/path_ops.rs | 91 +++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/path_ops.rs b/crates/ui-egui/src/dialogs/path_ops.rs index 12205dca03..c31f379d09 100644 --- a/crates/ui-egui/src/dialogs/path_ops.rs +++ b/crates/ui-egui/src/dialogs/path_ops.rs @@ -114,6 +114,7 @@ pub(crate) struct Open { op: PathOp, id: DialogId, document: u64, + reverts: u64, preview: LivePreview, /// A distinct selection snapshot identifies the interaction that ran this preview. preview_selection: Option>, @@ -371,6 +372,7 @@ impl Open { let Some(selection) = &self.preview_selection else { return false }; app.session.active().is_some_and(|state| { state.uid == self.document + && state.reverts == self.reverts && state.interaction.as_ref().is_some_and(|interaction| selection.as_ptr() == Arc::as_ptr(&interaction.selection)) }) } @@ -382,8 +384,11 @@ impl Open { } fn commit(&mut self, app: &mut VectorcraftApp, cmd: &str, params: Value) -> Result<(), String> { - if app.session.active().is_none_or(|state| state.uid != self.document) { + let Some(state) = app.session.active().filter(|state| state.uid == self.document) else { return Err(tl!("Return to the document where this dialog opened.").to_owned()); + }; + if state.reverts != self.reverts { + return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned()); } if app.session.in_interaction() && !self.owns_preview(app) { return Err(tl!("Finish the active edit before confirming.").to_owned()); @@ -471,6 +476,7 @@ fn open_dialog(app: &mut VectorcraftApp, op: PathOp, fields: DialogFields, remem if let Some(old) = take_open(app, op) { old.cancel(app); } + let reverts = app.session.active().map_or(0, |state| state.reverts); let id = if op.previews() { let cancel = Box::new(move |app: &mut VectorcraftApp| { // A cancelled opening can leave a replacement with the same dialog ID. @@ -494,6 +500,7 @@ fn open_dialog(app: &mut VectorcraftApp, op: PathOp, fields: DialogFields, remem op, id, document, + reverts, preview: LivePreview::default(), preview_selection: None, last: Value::Null, @@ -562,7 +569,7 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { fn step(app: &mut VectorcraftApp, r: &mut Open) { let Some((on, fields)) = dialog_state(app, r.id) else { return }; - let Some(state) = app.session.active().filter(|state| state.uid == r.document) else { return }; + let Some(state) = app.session.active().filter(|state| state.uid == r.document && state.reverts == r.reverts) else { return }; if !r.owns_preview(app) { r.preview = LivePreview::default(); r.preview_selection = None; @@ -796,6 +803,8 @@ mod split_tests { #[cfg(test)] mod preview_document_tests { + use craft::ui::dialog::HeldOk; + use super::*; use crate::dialogs::tests::{app, cancel, confirm, frame, set}; @@ -821,6 +830,84 @@ mod preview_document_tests { crate::dialogs::simplify_slider::more_options(app).unwrap(); } + fn show_path_options(app: &mut VectorcraftApp, op: PathOp) { + if op == PathOp::Simplify { + more_options(app); + } else { + crate::menus::invoke(app, op.key(), json!({})); + set(app, "offset", json!(12.0)); + } + set(app, "preview", json!(false)); + } + + fn path_options_after_revert(op: PathOp, hold_ok: bool) -> (VectorcraftApp, DialogId) { + let mut app = app(); + let id = if op == PathOp::Simplify { + dense_path(&mut app, 50.0) + } else { + app.run("shape.rectangle", json!({"x": 10, "y": 20, "width": 100, "height": 60})).unwrap()["id"].as_u64().unwrap() + }; + let folder = vectorcraft_testkit::TempDir::new("path-options-revert"); + let path = folder.join("paths.vectorcraft"); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|e| e.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|e| e.to_string()))); + app.run("file.saveAs", json!({"path": path})).unwrap(); + app.run("object.move", json!({"ids": [id], "dx": 5, "dy": 0})).unwrap(); + app.run("select.set", json!({"ids": [id]})).unwrap(); + let source = app.session.active().unwrap(); + let (uid, reverts) = (source.uid, source.reverts); + show_path_options(&mut app, op); + let dialog_id = app.object_dialogs.path.iter().find(|open| open.op == op).unwrap().id; + if hold_ok { + let ctx = app.ui_ctx.clone().unwrap(); + assert!(!app.dialogs().unwrap().with(|host| host.confirm_by_id(&ctx, dialog_id))); + } + app.run("file.revert", json!({"confirmed": true})).unwrap(); + let restored = app.session.active().unwrap(); + assert_eq!((restored.uid, restored.reverts), (uid, reverts + 1)); + assert!(restored.doc.node(NodeId(id)).is_some()); + app.run("select.set", json!({"ids": [id]})).unwrap(); + (app, dialog_id) + } + + #[test] + fn path_options_revert_drops_old_preview() { + for op in [PathOp::Simplify, PathOp::OffsetPath] { + let (mut app, _) = path_options_after_revert(op, false); + let restored = app.session.active().unwrap().doc.clone(); + set(&mut app, "preview", json!(true)); + frame(&mut app, vec![]); + assert!(app.session.active().unwrap().doc == restored, "the old path preview reached restored artwork"); + assert!(!app.session.in_interaction()); + } + } + + #[test] + fn path_options_revert_refuses_held_ok_and_accepts_a_new_opening() { + for op in [PathOp::Simplify, PathOp::OffsetPath] { + let (mut app, dialog) = path_options_after_revert(op, true); + let source = app.session.active().unwrap(); + let (restored, undo) = (source.doc.clone(), source.history.undo.len()); + frame(&mut app, vec![]); + let after = app.session.active().unwrap(); + assert!(after.doc == restored, "the old path OK reached restored artwork"); + assert_eq!(after.history.undo.len(), undo); + let held = app.dialogs().unwrap().with(|host| host.held_state(dialog)); + let Some(HeldOk::Refused(message)) = held else { panic!("expected a held refusal") }; + assert_eq!(message.as_str(), "The document was reverted. Reopen this dialog to continue."); + + assert!(cancel(&mut app)); + show_path_options(&mut app, op); + set(&mut app, "preview", json!(true)); + frame(&mut app, vec![]); + assert!(app.session.in_interaction(), "a new opening can preview the restored paths"); + assert!(confirm(&mut app)); + let after = app.session.active().unwrap(); + assert!(after.doc != restored, "the fresh OK applies the preview"); + assert_eq!(after.history.undo.len(), undo + 1); + } + } + #[test] fn simplify_options_skip_the_other_drawings_artwork() { for from_slider in [false, true] { From 6e40ce3c7e4f1c4fee09fea7d5eee6a8d1c5f583 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 21:50:54 -0800 Subject: [PATCH 04/48] Keep CJK settings with the opening text selection --- crates/ui-egui/src/dialogs/tate_chu_yoko.rs | 29 ++++++++++++- crates/ui-egui/src/dialogs/warichu.rs | 27 ++++++++++++- crates/ui-egui/src/panels/character.rs | 45 +++++++++++++++++++-- 3 files changed, 96 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/dialogs/tate_chu_yoko.rs b/crates/ui-egui/src/dialogs/tate_chu_yoko.rs index e2f32ef4fd..34eb857f53 100644 --- a/crates/ui-egui/src/dialogs/tate_chu_yoko.rs +++ b/crates/ui-egui/src/dialogs/tate_chu_yoko.rs @@ -39,6 +39,7 @@ fn rows(lengths: LengthUnits) -> Vec { /// Open Tate-chu-yoko Settings on the characters the Character panel acts on. pub fn open(app: &mut VectorcraftApp) -> Result { crate::panels::character::text_style(app).ok_or("select some type first")?; + let target = crate::panels::character::format_target_kept(app)?; let active = app.session.active().ok_or("no document")?; let (document, reverts) = (active.uid, active.reverts); let (up, right) = crate::panels::character::shared_tcy_offsets(app); @@ -65,7 +66,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result { if active.reverts != reverts { return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned()); } - crate::panels::character::run_format(app, Value::Object(p)).map(|_| ()) + crate::panels::character::run_format_at_target(app, Value::Object(p), &target).map(|_| ()) }) .ok_or("no window")?; Ok(Value::Null) @@ -206,6 +207,32 @@ mod tests { assert_eq!(offsets(&app, id), [(0.0, 6.0), (0.0, 0.0)]); } + #[test] + fn tate_chu_yoko_approval_keeps_its_opening_text_target() { + let (mut app, id) = app(); + let select = |app: &mut VectorcraftApp, anchor, caret| { + app.session.set_tool_option("textSelection", &json!({"editing": id, "anchor": anchor, "caret": caret})); + }; + app.session.select_tool("type", Default::default()).unwrap(); + select(&mut app, 0, 2); + let undo = app.session.active().unwrap().history.undo.len(); + app.run("ui.tateChuYokoSettings", json!({})).unwrap(); + driver::set(&mut app, "tcyLeftRight", json!(6)); + + select(&mut app, 2, 4); + assert_eq!(crate::panels::character::text_editing(&app), Some((NodeId(id), 2, 4))); + let dialog = craft::ui::dialog::dialog_id(KIND); + crate::tests::picks::answer_dialog(&mut app, dialog, &[], true); + assert_eq!(offsets(&app, id), [(0.0, 0.0)], "the new text range keeps its formatting"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert!(matches!(app.dialogs().unwrap().with(|h| h.held_state(dialog)), Some(craft::ui::dialog::HeldOk::Refused(_)))); + + select(&mut app, 0, 2); + assert!(crate::dialogs::tests::confirm(&mut app)); + assert_eq!(offsets(&app, id), [(0.0, 6.0), (0.0, 0.0)]); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1); + } + #[test] fn tate_chu_yoko_approval_refuses_to_change_restored_text() { let (mut app, id) = app(); diff --git a/crates/ui-egui/src/dialogs/warichu.rs b/crates/ui-egui/src/dialogs/warichu.rs index c297df5160..2001db0934 100644 --- a/crates/ui-egui/src/dialogs/warichu.rs +++ b/crates/ui-egui/src/dialogs/warichu.rs @@ -69,6 +69,7 @@ fn rows(lengths: LengthUnits) -> Vec { /// Open Warichu Settings on the characters the Character panel acts on. pub fn open(app: &mut VectorcraftApp) -> Result { crate::panels::character::text_style(app).ok_or("select some type first")?; + let target = crate::panels::character::format_target_kept(app)?; let active = app.session.active().ok_or("no document")?; let (document, reverts) = (active.uid, active.reverts); let shared = crate::panels::character::shared_warichu(app); @@ -96,7 +97,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result { if active.reverts != reverts { return Err(tl!("The document was reverted. Reopen this dialog to continue.").to_owned()); } - crate::panels::character::run_format(app, Value::Object(p)).map(|_| ()) + crate::panels::character::run_format_at_target(app, Value::Object(p), &target).map(|_| ()) }) .ok_or("no window")?; Ok(Value::Null) @@ -342,6 +343,30 @@ mod tests { assert_eq!(settings(&app, id), [(false, 2, 0.0, 50.0, WarichuAlign::JustifyAll), (false, 2, 0.0, 50.0, WarichuAlign::Auto)]); } + #[test] + fn warichu_approval_keeps_its_opening_text_target() { + let (mut app, first) = app(); + let second = app.run("text.create", json!({"x": 12, "y": 100, "text": "second"})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [first]})).unwrap(); + let before = settings(&app, second); + let undo = app.session.active().unwrap().history.undo.len(); + app.run("ui.warichuSettings", json!({})).unwrap(); + driver::set(&mut app, "warichuLines", json!(4)); + + app.run("select.set", json!({"ids": [second]})).unwrap(); + let dialog = craft::ui::dialog::dialog_id(KIND); + crate::tests::picks::answer_dialog(&mut app, dialog, &[], true); + assert_eq!(settings(&app, second), before, "the second text object keeps its formatting"); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert!(matches!(app.dialogs().unwrap().with(|h| h.held_state(dialog)), Some(craft::ui::dialog::HeldOk::Refused(_)))); + + app.run("select.set", json!({"ids": [first]})).unwrap(); + assert!(crate::dialogs::tests::confirm(&mut app)); + assert_eq!(settings(&app, first), [(false, 4, 0.0, 50.0, WarichuAlign::Auto)]); + assert_eq!(settings(&app, second), before); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1); + } + #[test] fn warichu_approval_refuses_to_change_restored_text() { let (mut app, id) = app(); diff --git a/crates/ui-egui/src/panels/character.rs b/crates/ui-egui/src/panels/character.rs index 6804b53c4d..bfcb770b7e 100644 --- a/crates/ui-egui/src/panels/character.rs +++ b/crates/ui-egui/src/panels/character.rs @@ -33,7 +33,7 @@ use egui::Ui; use serde_json::{Value, json}; use vectorcraft_doc::setup::{LANGUAGES, char_language_name}; use vectorcraft_doc::text::TypeAntiAlias; -use vectorcraft_doc::{CharStyle, NodeId, NodeKind}; +use vectorcraft_doc::{CharStyle, NodeId, NodeKind, SymbolPart}; use vectorcraft_engine::DocState; use vectorcraft_tools::{Mods, ToolKey}; @@ -289,8 +289,13 @@ pub(crate) fn format(app: &mut VectorcraftApp, p: Value) { /// [`format`] that returns the command's result: `text.setRangeStyle` on the range the Type tool /// has selected (the whole text when nothing is selected) while it edits text, else /// `text.setFormat` on the selected stories ([`selected_stories`]). -pub(crate) fn run_format(app: &mut VectorcraftApp, mut p: Value) -> Result { - let Some((id, a, b)) = text_editing_kept(app)? else { +pub(crate) fn run_format(app: &mut VectorcraftApp, p: Value) -> Result { + let editing = text_editing_kept(app)?; + run_format_after_typing(app, p, editing) +} + +fn run_format_after_typing(app: &mut VectorcraftApp, mut p: Value, editing: Option<(NodeId, usize, usize)>) -> Result { + let Some((id, a, b)) = editing else { target_selected_stories(app, &mut p); return app.run("text.setFormat", p); }; @@ -305,6 +310,40 @@ pub(crate) fn run_format(app: &mut VectorcraftApp, mut p: Value) -> Result, Option), + Story(Vec), + Range(NodeId, usize, usize), +} + +fn format_target(app: &VectorcraftApp, editing: Option<(NodeId, usize, usize)>) -> FormatTarget { + if let Some((id, start, end)) = editing { + return text_story(app).map_or(FormatTarget::Range(id, start, end), FormatTarget::Story); + } + let mut ids = selected_stories(app); + ids.sort_unstable_by_key(|id| id.0); + let part = app.session.active().and_then(|st| st.selection.symbol_part.clone()); + FormatTarget::Objects(ids, part) +} + +pub(crate) fn format_target_kept(app: &mut VectorcraftApp) -> Result { + let editing = text_editing_kept(app)?; + Ok(format_target(app, editing)) +} + +/// Apply a settings dialog to its opening text only. Compare before keeping typing so a +/// refused confirmation on different text does not commit that text's in-progress edit. +pub(crate) fn run_format_at_target(app: &mut VectorcraftApp, p: Value, target: &FormatTarget) -> Result { + let check = |current: FormatTarget| { + if ¤t != target { Err(tl!("The selected text changed. Restore the selection to continue.").to_owned()) } else { Ok(()) } + }; + check(format_target(app, text_editing(app)))?; + let editing = text_editing_kept(app)?; + check(format_target(app, editing))?; + run_format_after_typing(app, p, editing) +} + /// The Tate-chu-yoko Settings Up/Down and Left/Right the characters the panels act on share, in /// document points; `None` where they differ, or with no type. pub(crate) fn shared_tcy_offsets(app: &VectorcraftApp) -> (Option, Option) { From 7e9d9979fd7a4532036317205875dfafef378ec0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 22:09:34 -0800 Subject: [PATCH 05/48] Restore Action selector drafts after a canceled choice --- crates/ui-egui/src/dialogs/action_new.rs | 111 ++++++++++++++++++++++- crates/ui-egui/src/dialogs/actions.rs | 8 +- 2 files changed, 110 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/dialogs/action_new.rs b/crates/ui-egui/src/dialogs/action_new.rs index 58980c099c..dda71b4984 100644 --- a/crates/ui-egui/src/dialogs/action_new.rs +++ b/crates/ui-egui/src/dialogs/action_new.rs @@ -138,9 +138,7 @@ impl StackDialog for NewActionDialog { TextField::new(label("Name:"), Bind::bound(&mut fields.name)).show(ui); }); Field::new(label("Action Set:")).show(ui, |ui, _| { - if let Some(set) = Select::new(label("Action Set:"), Bind::given(fields.set), &sets).show(ui).value().copied() { - fields.set = set; - } + Select::new(label("Action Set:"), Bind::bound(&mut fields.set), &sets).show(ui); }); key_and_color(ui, &mut fields.options); automatic_align_options(ui, &mut fields.options); @@ -164,3 +162,110 @@ impl StackDialog for NewActionDialog { self.form.set_field(ctx, field, value) } } + +#[cfg(test)] +mod tests { + use craft::automation::actions::{ActionColor, ActionList}; + use craft::ui::contract::Role; + use egui::{Key, Modifiers}; + + use super::*; + use crate::dialogs::action_set_options::SetOptionsDialog; + use crate::panels::actions::{FUNCTION_KEYS, STOP_RECORDING, model}; + use crate::tests::panel_harness::Panel; + + fn panel() -> Panel { + let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default())); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + app.ui.actions = ActionList::new(); + app.ui.actions.new_set("First").unwrap(); + app.ui.actions.new_set("Second").unwrap(); + app.ui.action_set = Some("First".into()); + Panel::new(app, crate::tests::picks::dialogs) + } + + fn fields(panel: &Panel) -> NewActionFields { + panel.app().dialogs().unwrap().with(|host| host.get::().unwrap().form.values.clone()) + } + + fn popup(panel: &mut Panel, name: &str) { + panel.click_role(name, Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + } + + #[test] + fn cancelled_choices_keep_the_new_action_destination_key_and_color() { + let mut panel = panel(); + open(&mut panel.app()).unwrap(); + panel.frame(); + let original = fields(&panel); + for name in ["Action Set", "Function Key", "Color"] { + popup(&mut panel, name); + assert_ne!(fields(&panel), original, "the popup previews {name}"); + panel.key(Key::Escape, Modifiers::NONE); + panel.frame(); + assert_eq!(fields(&panel), original, "Escape restores {name}"); + } + assert!(panel.enabled("Record")); + panel.click("Record"); + panel.frame(); + panel.frame(); + { + let app = panel.app(); + assert!(app.ui.recording.is_some()); + assert_eq!(model::members(&app.ui.actions, "First").len(), 1); + assert!(model::members(&app.ui.actions, "Second").is_empty()); + let action = app.ui.actions.actions().first().unwrap(); + assert_eq!(action.name, original.name); + assert_eq!(action.color, ActionColor::None); + assert!(model::function_key(action).is_none()); + } + panel.app().run(STOP_RECORDING, json!({})).unwrap(); + crate::dialogs::action_set_options::open_action(&mut panel.app(), 0, 0); + panel.frame(); + let options = |panel: &Panel| panel.app().dialogs().unwrap().with(|host| host.get::().unwrap().json_fields().unwrap()); + let original = options(&panel); + for name in ["Function Key", "Color"] { + popup(&mut panel, name); + panel.key(Key::Escape, Modifiers::NONE); + panel.frame(); + assert_eq!(options(&panel), original, "Action Options restores {name}"); + } + panel.click("OK"); + panel.frame(); + let app = panel.app(); + let action = app.ui.actions.actions().first().unwrap(); + assert_eq!(action.color, ActionColor::None); + assert!(model::function_key(action).is_none()); + } + + #[test] + fn committed_choices_are_used_by_record() { + let mut panel = panel(); + open(&mut panel.app()).unwrap(); + panel.frame(); + popup(&mut panel, "Action Set"); + panel.key(Key::Enter, Modifiers::NONE); + popup(&mut panel, "Color"); + panel.key(Key::Enter, Modifiers::NONE); + let key = (1..=FUNCTION_KEYS).find(|&key| key_reason(&ActionOptions { key, ..Default::default() }).is_none()).unwrap(); + panel.click_role("Function Key", Role::COMBO_BOX); + panel.key(Key::Home, Modifiers::NONE); + for _ in 0..key { + panel.key(Key::ArrowDown, Modifiers::NONE); + } + panel.key(Key::Enter, Modifiers::NONE); + let chosen = fields(&panel); + assert_eq!((chosen.set, chosen.options.key, chosen.options.color), (1, key, ActionColor::ALL[1])); + panel.click("Record"); + panel.frame(); + panel.frame(); + let app = panel.app(); + assert!(model::members(&app.ui.actions, "First").is_empty()); + assert_eq!(model::members(&app.ui.actions, "Second").len(), 1); + let action = app.ui.actions.actions().first().unwrap(); + assert_eq!(action.color, chosen.options.color); + assert_eq!(model::function_key(action).map(|key| key.key), Some(key)); + assert!(app.ui.recording.is_some()); + } +} diff --git a/crates/ui-egui/src/dialogs/actions.rs b/crates/ui-egui/src/dialogs/actions.rs index 8a6de85fe4..10a0647fc9 100644 --- a/crates/ui-egui/src/dialogs/actions.rs +++ b/crates/ui-egui/src/dialogs/actions.rs @@ -243,9 +243,7 @@ pub(crate) fn key_and_color(ui: &mut Ui, options: &mut ActionOptions) { let modifier = if crate::keymap::platform() == craft::keymap::Platform::Mac { "⌘" } else { "Ctrl" }; Field::new(label("Function Key:")).show(ui, |ui, _| { Row::new().show(ui, |ui, _| { - if let Some(key) = Select::new(label("Function Key:"), Bind::given(options.key), &keys).show(ui).value().copied() { - options.key = key; - } + Select::new(label("Function Key:"), Bind::bound(&mut options.key), &keys).show(ui); Checkbox::new(Bind::bound(&mut options.cmd)).label(modifier).show(ui); Checkbox::new(Bind::bound(&mut options.shift)).label(label("Shift")).show(ui); }); @@ -255,9 +253,7 @@ pub(crate) fn key_and_color(ui: &mut Ui, options: &mut ActionOptions) { let colors: Vec> = ActionColor::ALL.into_iter().map(|color| Entry::new(color, label_color_label(color.label_color(), &words))).collect(); Field::new(label("Color:")).show(ui, |ui, _| { - if let Some(color) = Select::new(label("Color:"), Bind::given(options.color), &colors).show(ui).value().copied() { - options.color = color; - } + Select::new(label("Color:"), Bind::bound(&mut options.color), &colors).show(ui); }); } From ee446c8dcf5b4c88a6d7ba8442aaa5830ca45e22 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 22:09:51 -0800 Subject: [PATCH 06/48] Keep symbol instance effects from its part selection --- .../panels/properties/appearance_section.rs | 13 ++++++---- crates/ui-egui/src/panels/properties/tests.rs | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/properties/appearance_section.rs b/crates/ui-egui/src/panels/properties/appearance_section.rs index b3266b032d..bd0c4d68b2 100644 --- a/crates/ui-egui/src/panels/properties/appearance_section.rs +++ b/crates/ui-egui/src/panels/properties/appearance_section.rs @@ -61,6 +61,7 @@ fn opacity_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { /// The fx button that opens the effect menu, as the Appearance panel's does, the Delete icon and /// the icon that shows the Appearance panel. fn effects_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { + let editable = app.session.active().is_some_and(|st| st.selection.symbol_part.is_none()); // The effects of one selected object: the fill's and stroke's as well as its own. let effects: Vec<(Option, usize, &str)> = if panels::selection_len(app) == 1 { let own = n.appearance.effects.iter().enumerate().map(|(k, e)| (None, k, e.id.as_str())); @@ -71,9 +72,11 @@ fn effects_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { vec![] }; Row::new().show(ui, |ui, _| { - let fx = Button::new("fx").tooltip(tl!("Add New Effect")).show(ui); - Menu::new(tl!("Add New Effect")).opened_by(&fx.response, Trigger::Click).show(ui, |ui, _| appearance::fx_menu(app, ui)); - effect_delete(app, ui, n.id, &effects); + let fx = Button::new("fx").tooltip(tl!("Add New Effect")).enabled(editable).show(ui); + if editable { + Menu::new(tl!("Add New Effect")).opened_by(&fx.response, Trigger::Click).show(ui, |ui, _| appearance::fx_menu(app, ui)); + } + effect_delete(app, ui, n.id, &effects, editable); panel_button("ellipsis", "appearance", tl!("Appearance panel")).show(ui); }); } @@ -82,12 +85,12 @@ fn effects_row(app: &mut VectorcraftApp, ui: &mut Ui, n: &Node) { /// (): /// with one effect applied, its name and an icon that removes it (`effect.remove`); with several, /// the icon shows the Appearance panel to remove them there. Nothing without effects. -fn effect_delete(app: &mut VectorcraftApp, ui: &mut Ui, id: NodeId, effects: &[(Option, usize, &str)]) { +fn effect_delete(app: &mut VectorcraftApp, ui: &mut Ui, id: NodeId, effects: &[(Option, usize, &str)], editable: bool) { match effects { [] => {} [(item, k, effect)] => { Text::new(appearance::shown_effect_label(effect)).elide(Elide::End).show(ui); - if IconButton::new(IconId::new("trash-2")).label(tl!("Remove Effect")).show(ui).clicked() { + if IconButton::new(IconId::new("trash-2")).label(tl!("Remove Effect")).enabled(editable).show(ui).clicked() { app.run("effect.remove", json!({"ids": [id.0], "item": item, "index": k})).ok(); } } diff --git a/crates/ui-egui/src/panels/properties/tests.rs b/crates/ui-egui/src/panels/properties/tests.rs index faeb91c166..bb50b38a58 100644 --- a/crates/ui-egui/src/panels/properties/tests.rs +++ b/crates/ui-egui/src/panels/properties/tests.rs @@ -1300,6 +1300,32 @@ fn one_effect_has_a_delete_icon_in_appearance() { assert!(!panel.shows(&name), "two objects"); } +#[test] +fn properties_remove_effect_requires_the_whole_symbol_instance() { + let mut app = new_app(); + let left = rect(&mut app, 20.0, 20.0, 20.0, 20.0); + let right = rect(&mut app, 60.0, 20.0, 20.0, 20.0); + let instance = app.run("symbol.new", json!({"type": "dynamic", "ids": [left, right]})).unwrap()["id"].clone(); + let node = vectorcraft_doc::NodeId(instance.as_u64().unwrap()); + app.run("effect.apply", json!({"ids": [instance], "effect": "stylize.dropShadow"})).unwrap(); + app.run("symbol.instance.selectPart", json!({"id": instance, "path": [0]})).unwrap(); + let mut panel = Panel::new(app, show); + let effects = |panel: &Panel| panel.app().session.active().unwrap().doc.node(node).unwrap().appearance.effects.len(); + let depth = undo_depth(&panel.app()); + + assert_eq!(effects(&panel), 1); + panel.click("Remove Effect"); + assert_eq!((effects(&panel), undo_depth(&panel.app())), (1, depth), "a part cannot remove the whole instance’s effect"); + assert!(!panel.enabled("Remove Effect")); + assert!(panel.shows("Appearance panel"), "Appearance remains available for inspection"); + + panel.app().run("select.set", json!({"ids": [instance]})).unwrap(); + panel.frame(); + assert!(panel.enabled("Remove Effect")); + panel.click("Remove Effect"); + assert_eq!((effects(&panel), undo_depth(&panel.app())), (0, depth + 1)); +} + /// A rectangle at 100, 100, 100 × 60 pt, selected, with `then` run on it, and the Transform /// panel's reference point on the top-left square. fn reference_setup(then: &[(&str, Value)]) -> VectorcraftApp { From 4940fddf0b988937ee9d317463c0cfbc3edc8326 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 21:55:02 -0800 Subject: [PATCH 07/48] Keep instance mask controls off a selected symbol part --- crates/ui-egui/src/panels/tests_maskview.rs | 37 +++++++++++++++++++++ crates/ui-egui/src/panels/transparency.rs | 6 ++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/tests_maskview.rs b/crates/ui-egui/src/panels/tests_maskview.rs index c6479f1d23..43c3f27de8 100644 --- a/crates/ui-egui/src/panels/tests_maskview.rs +++ b/crates/ui-egui/src/panels/tests_maskview.rs @@ -33,6 +33,43 @@ fn click_mask(panel: &mut Panel, mods: Modifiers) { panel.click_part(ROW, ThumbTarget::Extra(0).part(), mods); } +#[test] +fn the_mask_thumbnail_only_edits_the_whole_symbol_instance() { + for mods in [Modifiers::ALT, Modifiers::NONE] { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + run(&mut app, "file.new", json!({"width": 100, "height": 100})); + let rect = |app: &mut VectorcraftApp, x| run(app, "shape.rectangle", json!({"x": x, "y": 10, "width": 20, "height": 20}))["id"].clone(); + let left = rect(&mut app, 10); + let right = rect(&mut app, 50); + let symbol = run(&mut app, "symbol.new", json!({"name": "Pair", "type": "dynamic", "ids": [left, right]}))["id"].clone(); + let mask = rect(&mut app, 20); + run(&mut app, "transparency.makeOpacityMask", json!({"ids": [symbol, mask]})); + run(&mut app, "symbol.instance.selectPart", json!({"id": symbol, "path": [0]})); + let mut panel = Panel::new(app, transparency::show); + let undo = panel.app().session.active().unwrap().history.undo.len(); + + click_mask(&mut panel, mods); + { + let app = panel.app(); + let st = app.session.active().unwrap(); + assert!(st.doc.mask_edit.is_none() && st.shown_mask().is_none(), "the part cannot enter the instance mask with {mods:?}"); + assert_eq!(st.history.undo.len(), undo); + assert!(st.selection.symbol_part.is_some()); + } + for label in ["Release", "Clip", "Invert Mask", "Isolate Blending", "Knockout Group", "Opacity & Mask Define Knockout Shape"] { + assert!(!panel.enabled(label), "{label} applies to the whole instance"); + } + assert!(panel.enabled("Opacity") && panel.enabled("Blend Mode")); + + run(&mut panel.app(), "select.set", json!({"ids": [symbol]})); + click_mask(&mut panel, mods); + let app = panel.app(); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.mask_edit.map(|edit| edit.object.0), symbol.as_u64()); + assert_eq!(st.shown_mask().map(|id| id.0), mods.alt.then(|| symbol.as_u64().unwrap())); + } +} + /// In pattern editing mode a click or an Alt-click on the mask thumbnail of a masked object in the /// tile does not edit the mask, and the status bar says to finish editing the pattern first. Make /// Mask is off for one object, which it would take into mask editing. After Done a click edits the diff --git a/crates/ui-egui/src/panels/transparency.rs b/crates/ui-egui/src/panels/transparency.rs index 3f6e38014b..72a2223707 100644 --- a/crates/ui-egui/src/panels/transparency.rs +++ b/crates/ui-egui/src/panels/transparency.rs @@ -78,10 +78,10 @@ pub(crate) fn state(app: &mut VectorcraftApp) -> (TransparencyInfo, Option bool { - editing || app.session.appearance_item().is_none() + editing || (app.session.appearance_item().is_none() && !app.session.active().is_some_and(|st| st.selection.symbol_part.is_some())) } /// The key of one mask-row thumbnail: the masked object, the background it sits on and which picture it is. From 40aadc491c1a2cd9b6903e827637820c23c908a2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 22:15:16 -0800 Subject: [PATCH 08/48] Keep selected Relink instances after a canceled scope choice --- crates/ui-egui/src/dialogs/relink.rs | 64 ++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/relink.rs b/crates/ui-egui/src/dialogs/relink.rs index ac99cf9b0c..7220750be8 100644 --- a/crates/ui-egui/src/dialogs/relink.rs +++ b/crates/ui-egui/src/dialogs/relink.rs @@ -256,9 +256,7 @@ impl StackDialog for RelinkDialog { } }); Field::new(tl!("Replace:")).show(ui, |ui, _| { - if let Some(next) = Select::new(tl!("Replace:"), Bind::given(scope.clone()), &entries).show(ui).value().cloned() { - *scope = next; - } + Select::new(tl!("Replace:"), Bind::bound(scope), &entries).show(ui); }); true }); @@ -453,6 +451,66 @@ mod tests { check_relink_stays_in_opening_drawing(true); } + #[test] + fn replace_popup_cancel_preserves_selected_instances_and_enter_relinks_all() { + use crate::tests::panel_harness::Panel; + use craft::ui::contract::Role; + use egui::{Key, Modifiers}; + + struct Scratch(std::path::PathBuf); + impl Drop for Scratch { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } + } + + for commit in [false, true] { + let (mut app, dir) = setup(if commit { "popup-commit" } else { "popup-cancel" }, &["photo.png", "other.png"]); + let _scratch = Scratch(dir.clone()); + let a = place(&mut app, &dir.join("photo.png")); + let b = place(&mut app, &dir.join("photo.png")); + let c = place(&mut app, &dir.join("other.png")); + let picker = scripted(&mut app); + let chosen = new_file(&dir, "replacement.png"); + let original_path = dir.join("photo.png").to_string_lossy().into_owned(); + let other_path = link_path(&app, c); + let original = app.session.active().unwrap().doc.clone(); + let revision = app.session.active().unwrap().revision; + let undo = app.session.active().unwrap().history.undo.len(); + let mut panel = Panel::new(app, crate::tests::picks::dialogs); + panel.room(egui::vec2(900.0, 700.0)); + panel.app().run("ui.relinkDialog", json!({"ids": [a]})).unwrap(); + panel.frame(); + let before = fields(&panel.app()); + panel.click_role("Replace:", Role::COMBO_BOX); + panel.key(Key::ArrowDown, Modifiers::NONE); + assert_eq!(fields(&panel.app())["scope"], "all", "the open popup previews All Instances"); + panel.key(if commit { Key::Enter } else { Key::Escape }, Modifiers::NONE); + assert_eq!(fields(&panel.app())["scope"], if commit { "all" } else { "selected" }); + if !commit { + assert_eq!(fields(&panel.app()), before, "Escape preserves all pending Relink fields"); + } + assert_eq!(panel.app().session.active().unwrap().doc, original); + assert_eq!(panel.app().session.active().unwrap().revision, revision); + assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo); + panel.click("Relink…"); + assert_eq!(picker.requests().len(), 1); + picker.answer(&[&chosen]); + panel.frame(); + panel.frame(); + assert!(open_dialogs(&panel.app()).is_empty()); + { + let app = panel.app(); + assert_eq!(link_path(&app, a), chosen); + assert_eq!(link_path(&app, b), if commit { chosen.clone() } else { original_path.clone() }); + assert_eq!(link_path(&app, c), other_path); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo + 1); + } + panel.app().run("edit.undo", json!({})).unwrap(); + assert_eq!(panel.app().session.active().unwrap().doc, original); + } + } + #[test] fn relink_opens_with_the_replace_choice_and_all_instances_relinks_every_copy() { let (mut app, dir) = setup("all", &["photo.png", "other.png"]); From 3498066d9347c132d86fa54832f8d43f1a99a50d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 22:15:17 -0800 Subject: [PATCH 09/48] Keep Artboard Options geometry drafts local until commit --- .../ui-egui/src/dialogs/artboard_options.rs | 113 +++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/artboard_options.rs b/crates/ui-egui/src/dialogs/artboard_options.rs index 1e3013b69a..8cb212aebb 100644 --- a/crates/ui-egui/src/dialogs/artboard_options.rs +++ b/crates/ui-egui/src/dialogs/artboard_options.rs @@ -351,7 +351,8 @@ fn length_row(ui: &mut Ui, label: impl Into