From ce124a6716781796687288ec46b4e42b2027f600 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 18:03:00 -0800 Subject: [PATCH] Map Art: the surface list is kept per document The cached list of Map Art's surfaces was keyed by the object's id, the effect settings and the document's revision. Another open document whose object had the same id and revision then showed the first document's surface count and outlines. The key now includes the document's uid, as the other per-document caches in the UI do. --- .../ui-egui/src/dialogs/tests_track_cube.rs | 34 +++++++++++++++++++ crates/ui-egui/src/dialogs/three_d_classic.rs | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/tests_track_cube.rs b/crates/ui-egui/src/dialogs/tests_track_cube.rs index 9b99efb105..9e36fb89f0 100644 --- a/crates/ui-egui/src/dialogs/tests_track_cube.rs +++ b/crates/ui-egui/src/dialogs/tests_track_cube.rs @@ -182,3 +182,37 @@ fn grips_follow_what_is_under_the_pointer() { let m = rotation([0.0, 0.0, 0.0]); assert_eq!(edges().filter(|&(i, _, axis)| edge_visible(m, i, axis)).count(), 4); } + +/// Map Art lists each document's own surfaces: after a switch to another document whose object has +/// the same id, effect settings and revision, the surfaces are those of the other document's object. +#[test] +fn map_art_surfaces_follow_the_active_document() { + let mut app = crate::VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + for d in ["M50 50L150 50L150 150L50 150Z", "M50 50L80 50L80 200L50 200Z"] { + app.run("file.new", json!({"width":300,"height":300})).unwrap(); + app.run("path.create", json!({"d": d})).unwrap(); + } + app.run("effect.dialog", json!({"effect":CLASSIC_EXTRUDE,"item":null})).unwrap(); + let d = app.ui.dialog.take().unwrap(); + let ctx = egui::Context::default(); + let key = |app: &crate::VectorcraftApp| { + let st = app.session.active().unwrap(); + (st.selection.objects.first().copied(), st.revision) + }; + let second = surfaces(&app, &ctx, &d).unwrap(); + let at_second = key(&app); + assert!(app.session.set_active(0)); + assert_eq!(key(&app), at_second, "both documents' objects have the same id and revision"); + let first = surfaces(&app, &ctx, &d).unwrap(); + let st = app.session.active().unwrap(); + let id = st.selection.objects[0]; + let own = vectorcraft_effects::map_surfaces_with( + Some(&st.doc), + st.doc.node(id).unwrap(), + (None, None), + CLASSIC_EXTRUDE, + &super::super::form::params(&d), + ); + assert_ne!(first, second, "the two objects' solids differ in size"); + assert_eq!(Some(first.as_ref()), own.as_ref(), "the first document's surfaces"); +} diff --git a/crates/ui-egui/src/dialogs/three_d_classic.rs b/crates/ui-egui/src/dialogs/three_d_classic.rs index 4529abf6c5..534389642d 100644 --- a/crates/ui-egui/src/dialogs/three_d_classic.rs +++ b/crates/ui-egui/src/dialogs/three_d_classic.rs @@ -70,7 +70,7 @@ fn surfaces(app: &crate::VectorcraftApp, ctx: &egui::Context, d: &Dialog) -> Opt // The effect being edited, when the dialog edits one already on the object. let index = d.fields.get("__index").and_then(Value::as_u64).map(|i| i as usize); let mut hasher = std::collections::hash_map::DefaultHasher::new(); - (id.0, item, index, &effect, p.to_string(), st.revision).hash(&mut hasher); + (st.uid, id.0, item, index, &effect, p.to_string(), st.revision).hash(&mut hasher); let key = hasher.finish(); let cache = egui::Id::unique("map-art-surfaces"); if let Some((at, kept)) = ctx.data(|m| m.get_temp::<(u64, std::sync::Arc>)>(cache))