From 20ac8c7f08fd5b9d6ca30865d0bf569d5d4d18e0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 15:21:45 -0800 Subject: [PATCH] Keep Expand attached to its original drawing --- crates/ui-egui/src/dialogs/expand.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/expand.rs b/crates/ui-egui/src/dialogs/expand.rs index f63e3e1641..0f61119fc8 100644 --- a/crates/ui-egui/src/dialogs/expand.rs +++ b/crates/ui-egui/src/dialogs/expand.rs @@ -154,7 +154,14 @@ fn dialog(app: &VectorcraftApp, info: ExpandInfo) -> Result Result { - crate::dialogs::host::open_held(app, dialog, ok).ok_or("no window")?; + let document = app.session.active().ok_or("no document open")?.uid; + crate::dialogs::host::open_held(app, dialog, move |app, result: &ParamResult| { + if app.session.active().is_none_or(|st| st.uid != document) { + return Err(tl!("Return to the original drawing to expand the artwork").into()); + } + ok(app, result) + }) + .ok_or("no window")?; Ok(Value::Null) } @@ -285,6 +292,24 @@ mod tests { assert!(matches!(children[1].kind, NodeKind::Mesh(_))); } + #[test] + fn expand_keeps_its_draft_when_another_drawing_is_active() { + let mut app = app(); + gradient_rectangle(&mut app); + open(&mut app).unwrap(); + set(&app, "gradient", json!("mesh")).unwrap(); + gradient_rectangle(&mut app); + let undo = app.session.active().unwrap().history.undo.len(); + let before = app.session.active().unwrap().doc.clone(); + assert!(matches!(press_ok(&mut app), Some(HeldOk::Refused(reason)) if reason.as_str().contains("original drawing"))); + assert_eq!(app.session.active().unwrap().history.undo.len(), undo); + assert!(std::sync::Arc::ptr_eq(&app.session.active().unwrap().doc, &before)); + assert_eq!(fields(&app).text("gradient"), Some("mesh")); + app.run("document.activate", json!({"index": 0})).unwrap(); + ok_and_close(&mut app); + assert!(expanded_to_a_mesh(&app)); + } + #[test] fn expand_gradient_to_is_disabled_for_a_pattern_fill_alone() { let mut app = app();