From 79d9e1e1ab6f73a5f7bba8273c19286a93ba50a4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 17:59:31 -0800 Subject: [PATCH] Guard Symbol Options against later selections and reverted drawings --- crates/ui-egui/src/dialogs/symbol_options.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/dialogs/symbol_options.rs b/crates/ui-egui/src/dialogs/symbol_options.rs index 89e2e0135a..e4282e51e6 100644 --- a/crates/ui-egui/src/dialogs/symbol_options.rs +++ b/crates/ui-egui/src/dialogs/symbol_options.rs @@ -12,6 +12,8 @@ //! Help: //! . +use std::collections::HashSet; + use craft::ui::contract::{Bind, Outcome as _, Show as _}; use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult}; use craft::ui::pickers::{Anchor9, ReferencePoint, ReferencePointLook}; @@ -100,13 +102,23 @@ fn rows(name: &str) -> Vec { /// edited), applies the fields to it; `keep_art` leaves the selection as ordinary art for a new one; /// `opened` are the guides the dialog opened with. fn open_dialog(app: &mut VectorcraftApp, fields: DialogFields, edit: Option, keep_art: bool, opened: [f64; 4]) -> Result { - let document = app.session.active().ok_or("no document open")?.uid; + let st = app.session.active().ok_or("no document open")?; + let (document, reverts) = (st.uid, st.reverts); + let selection = edit.is_none().then(|| st.selection.objects.iter().copied().collect::>()); let ctx = app.ui_ctx.clone().ok_or("no window")?; let name = fields.text("name").unwrap_or_default().to_string(); let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |_| ParamDialog::new(KIND, tl!("Symbol Options"), rows(&name))); let ok = move |app: &mut VectorcraftApp, result: &ParamResult| -> Result<(), String> { - if !app.session.active().is_some_and(|active| active.uid == document) { - return Err(tl!("This symbol belongs to the document that opened the dialog.").to_owned()); + let Some(active) = app.session.active().filter(|st| st.uid == document) else { + return Err(tl!("This symbol belongs to the document that opened the dialog.").into()); + }; + if active.reverts != reverts { + return Err(tl!("The document was reverted. Reopen this dialog to continue.").into()); + } + if let Some(selection) = &selection + && (active.selection.objects.len() != selection.len() || active.selection.objects.iter().any(|id| !selection.contains(id))) + { + return Err(tl!("The selected artwork changed. Restore the selection to continue.").into()); } let f = &result.fields; let name = f.text("name").unwrap_or_default().trim().to_string(); @@ -243,7 +255,7 @@ mod document_tests { let undo = app.session.active().unwrap().history.undo.len(); answer_dialog(&mut app, id, &[], true); - assert_eq!(app.session.active().unwrap().doc, before, "OK cannot turn the later selection into a symbol"); + assert!(app.session.active().unwrap().doc == before, "OK cannot turn the later selection into a symbol"); assert_eq!(app.session.active().unwrap().history.undo.len(), undo); app.run("select.set", json!({"ids": [original]})).unwrap();