From 55e323ce3a1ebe68fe34eb48550adc3109b1b443 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 06:45:08 -0800 Subject: [PATCH] Command dialogs: restrict edits to their target document --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/dialogs/command.rs | 62 +++++++++++++++++++++++-- crates/ui-egui/src/menus/ui_commands.rs | 2 +- docs/mcp.md | 5 ++ docs/target-app-parity.md | 2 + 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index fa2bc204f6..7394f0ea07 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -988,7 +988,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.paramDialog", "Command Dialog", "", - "{command, label?, params} open a parameter dialog for any command. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed", + "{command, label?, params} open a parameter dialog for any command. For commands other than edit.findReplace, params.__doc may be an unsigned document uid: the dialog previews and confirms only while that document is active, and OK after a document switch closes it without running the command. An invalid __doc is an error; omitting it keeps the existing behavior. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed", ), ( "ui.recolorDialog", diff --git a/crates/ui-egui/src/dialogs/command.rs b/crates/ui-egui/src/dialogs/command.rs index 97965e26dc..720bf3cbac 100644 --- a/crates/ui-egui/src/dialogs/command.rs +++ b/crates/ui-egui/src/dialogs/command.rs @@ -44,6 +44,8 @@ struct Open { preview: LivePreview, /// Set Role Swatch: the role the Swatch row was last filled for. filled_for: Option, + /// The document whose objects the dialog edits, when its caller supplies `__doc`. + doc: Option, /// Names this dialog's own open among reopenings of the same command, for its OK and Cancel. token: Arc<()>, } @@ -66,10 +68,16 @@ impl Setting { } /// Opens the parameter dialog of `command`, headed `label`, on `params` (a menu item's own values, `__params` for the -/// fixed ones and `__rowGutterLinked` for Area Type Options' linked Row Gutter). +/// fixed ones, `__rowGutterLinked` for Area Type Options' linked Row Gutter, and `__doc` for a document uid). pub(crate) fn open(app: &mut VectorcraftApp, command: &str, label: &str, mut params: Map) -> Result { + let doc = match params.remove("__doc") { + None => None, + Some(value) => Some(value.as_u64().ok_or("`__doc` must be a document id")?), + }; let ctx = app.ui_ctx.clone().ok_or("no window")?; - if let Some(old) = app.command_dialog.open.take() { + if let Some(old) = app.command_dialog.open.take() + && on_document(app, &old) + { old.preview.cancel(app); } let fixed = match params.remove("__params") { @@ -104,6 +112,7 @@ pub(crate) fn open(app: &mut VectorcraftApp, command: &str, label: &str, mut par previews, preview: LivePreview::default(), filled_for: None, + doc, token, }); Ok(Value::Null) @@ -121,6 +130,9 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { } fn step(app: &mut VectorcraftApp, open: &mut Open) { + if !on_document(app, open) { + return; + } let Some(dialogs) = app.dialogs() else { return }; let id = open.id; let seen = dialogs.with(|h| h.get_by_id::(id).map(|d| (d.fields().clone(), d.is_previewing()))); @@ -165,6 +177,9 @@ fn step(app: &mut VectorcraftApp, open: &mut Open) { /// error keeps it open with the reason under its rows. fn confirm(app: &mut VectorcraftApp, token: &Arc<()>, fields: &DialogFields) -> Result { let open = app.command_dialog.open.take_if(|o| Arc::ptr_eq(&o.token, token)).ok_or("the dialog is gone")?; + if !on_document(app, &open) { + return Ok(Value::Null); + } let params = command_params(&open.command, &open.opening, Setting::of(app)); let value = call(&open.command, &open.fixed, open.linked, form::json_of(¶ms, fields)); let result = if open.previews { @@ -185,11 +200,17 @@ fn confirm(app: &mut VectorcraftApp, token: &Arc<()>, fields: &DialogFields) -> /// Cancel: rolls back the preview of the dialog `token` names. fn cancel(app: &mut VectorcraftApp, token: &Arc<()>) { - if let Some(open) = app.command_dialog.open.take_if(|o| Arc::ptr_eq(&o.token, token)) { + if let Some(open) = app.command_dialog.open.take_if(|o| Arc::ptr_eq(&o.token, token)) + && on_document(app, &open) + { open.preview.cancel(app); } } +fn on_document(app: &VectorcraftApp, open: &Open) -> bool { + open.doc.is_none_or(|uid| app.session.active().is_some_and(|st| st.uid == uid)) +} + /// The rows of `command`'s dialog: one per value it opens with that the command takes, in `order(command)` first and /// the rest by name, Area Type Options' Text Flow last. fn command_params(command: &str, opening: &Map, setting: Setting) -> Vec { @@ -742,6 +763,41 @@ mod tests { /// The choices this dialog lists for Rasterize, Create Gradient Mesh and Repeat Options are the /// values their commands take (#8020, #7991): each one runs, and every language with complete + #[test] + fn document_scoped_dialog_confirms_only_in_its_opening_document() { + for (scoped, switch) in [(true, false), (true, true), (false, true)] { + let mut app = windowed(); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let mut params = json!({"x": 10, "y": 10, "width": 20, "height": 20}).as_object().unwrap().clone(); + if scoped { + params.insert("__doc".into(), json!(app.session.active().unwrap().uid)); + } + open(&mut app, "shape.rectangle", "Rectangle", params).unwrap(); + pump(&mut app); + if switch { + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + } + answer_ok(&mut app); + assert!(app.command_dialog.open.is_none()); + assert_eq!(app.session.active().unwrap().selection.is_empty(), scoped && switch); + if switch { + assert!(app.session.set_active(0)); + assert!(app.session.active().unwrap().selection.is_empty()); + } + } + } + + #[test] + fn document_scoped_dialog_rejects_an_invalid_document_id() { + for doc in [json!(null), json!("1"), json!(-1), json!(1.5)] { + let mut app = windowed(); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let params = json!({"width": 20, "height": 20, "__doc": doc}).as_object().unwrap().clone(); + assert!(open(&mut app, "shape.rectangle", "Rectangle", params).is_err(), "{doc}"); + assert!(app.command_dialog.open.is_none()); + } + } + /// menus has a row for each label. #[test] fn choice_fields_list_the_values_their_commands_take() { diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 7dcbb1d05d..b16211a756 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -989,7 +989,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.paramDialog", "Command Dialog", "", - "{command, label?, params} open a parameter dialog for any command. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed", + "{command, label?, params} open a parameter dialog for any command. For commands other than edit.findReplace, params.__doc may be an unsigned document uid: the dialog previews and confirms only while that document is active, and OK after a document switch closes it without running the command. An invalid __doc is an error; omitting it keeps the existing behavior. For edit.findReplace it opens Find and Replace (dialog `findReplace`), which stays open: fields find, replace, matchCase, wholeWord, backwards, hiddenLayers, lockedLayers, and action, which ui.dialog.confirm runs: find (the next match, edit.findNext, shown in the dialog with its place among the matches), replace (the match found, edit.replaceMatch), replaceFind (both), replaceAll (edit.findReplace) or done (close). After each one action is find again. Replace and Replace & Find change a match that find reached with the find text and options as they are now, and find one otherwise. The dialog opens on the last search, with the fields params gives in its place (a null field gives none; a field of the wrong type is an error, and ui.dialog.confirm then runs no action), and Edit › Find Next goes on from it in the same document while the dialog is closed", ), ( "ui.recolorDialog", diff --git a/docs/mcp.md b/docs/mcp.md index 437569a1f9..c45ba8d7d1 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -12389,6 +12389,11 @@ the dialog on the last search, with the fields its `params` give in its place. A the wrong type is an error that leaves the dialog closed. Once it is open, `ui.dialog.confirm` with a field of the wrong type runs no action and returns the error. +For other command dialogs, `params.__doc` can supply a document uid. The dialog previews and confirms only while +that document is active. Confirming after a document switch closes the dialog without running its command. +Canceling or replacing that dialog does not cancel an interaction in another document. A supplied `__doc` must be +an unsigned integer; omitting it preserves the command dialog's existing behavior. + ## Justification options diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 043ae5c403..d20559a4c6 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -32,6 +32,8 @@ ## Feature submission evidence +- Command dialogs can keep the uid of the document they edit. Their preview, confirmation, and cancellation do not change another active document. Tests cover confirmation in the original and another document, unscoped dialogs, and invalid document ids. + Variables panel row context menus (2026-11-20, G12): Right-click highlights the clicked variable without changing the canvas selection and offers Select Bound Object, Variable Options…, Unbind Variable, the four Make Dynamic actions, and Delete Variable. Shift+F10 opens the same menu for the focused row; Escape dismisses it. Row actions target that variable; dynamic actions use the canvas selection. Lock and selection checks disable unavailable actions. Headless pointer/accessibility tests cover opening the menu, highlighting, bound-object selection, deletion in one undo step and restoration, and disabled actions. Scores and estimates unchanged. Actions panel item context menus (2026-11-20): Right-clicking an Action Set row selects it and presents a context menu with New Action…, New Set…, Duplicate Set, Delete Set, and Set Options…. Right-clicking an Action row selects it and presents a context menu with Play, Record, Duplicate, Delete, Action Options…, and Batch…. Duplicate on an action duplicates that action and selects the duplicate; Delete removes it. Headless tests in `crates/ui-egui/src/panels/actions.rs`: `right_clicking_an_action_set_selects_it_and_presents_set_context_options`, `right_clicking_an_action_selects_it_and_presents_action_options`, and `clicking_duplicate_on_an_action_duplicates_that_action_in_the_set`. Scores and estimates unchanged.