From 7a5fa63be0a998e912542d08b2d6cf4db5f546f4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 19:26:16 -0800 Subject: [PATCH] Plug-ins: a command's dialog opens only for no params or `ids` alone A plug-in command with parameters, invoked with a number, a string, a list or a non-list `ids`, opened its dialog at the defaults and dropped what it was given. Such params now go to the command as they were given. --- crates/ui-egui/src/dialogs/plugin.rs | 2 +- crates/ui-egui/src/tests/plugins.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/plugin.rs b/crates/ui-egui/src/dialogs/plugin.rs index ce4878e782..83ab829440 100644 --- a/crates/ui-egui/src/dialogs/plugin.rs +++ b/crates/ui-egui/src/dialogs/plugin.rs @@ -719,7 +719,7 @@ struct CommandRun { /// step. The dialog runs only on the document that was active when it opened. False for any other /// command or params, which then run as they were given. pub fn open_command(app: &mut VectorcraftApp, id: &str, p: &Value) -> bool { - let only_ids = p.as_object().is_none_or(|o| o.keys().all(|k| k == "ids")) && p.get("ids").is_none_or(Value::is_array); + let only_ids = (p.is_null() || p.as_object().is_some_and(|o| o.keys().all(|k| k == "ids"))) && p.get("ids").is_none_or(Value::is_array); if !only_ids { return false; } diff --git a/crates/ui-egui/src/tests/plugins.rs b/crates/ui-egui/src/tests/plugins.rs index 6275d3cf58..e4bb835de2 100644 --- a/crates/ui-egui/src/tests/plugins.rs +++ b/crates/ui-egui/src/tests/plugins.rs @@ -872,6 +872,27 @@ fn a_plugin_command_dialog_stays_with_its_document() { h.state_mut().run("plugin.remove", json!({"id": id})).unwrap(); } +/// A command with parameters given params that are neither nothing nor an object of `ids` alone +/// opens no dialog: they go to the command as they were given, and it changes nothing. +#[test] +fn a_plugin_command_given_other_params_opens_no_dialog() { + let mut h = window(app()); + let id = "test.ui.context.params"; + let size = vectorcraft_engine::cmd::plugin::command_id(id, "size"); + let commands = r#"[{"id":"size","label":"Size","params":{"by":{"type":"number","min":0,"max":10,"default":2}}}]"#; + let app = h.state_mut(); + app.run("plugin.install", json!({"dataBase64": context_plugin(id, commands)})).unwrap(); + let target = red_rect(app); + let undo = app.session.doc().unwrap().history.undo.len(); + for p in [json!(5), json!("by"), json!([target.0]), json!({"ids": target.0})] { + menus::invoke(h.state_mut(), &size, p.clone()); + step(&mut h); + assert!(h.state().plugin_dialog.is_none(), "{p} opens no dialog"); + assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo, "{p} changes nothing"); + } + h.state_mut().run("plugin.remove", json!({"id": id})).unwrap(); +} + /// The `grant` and `allowHeavy` that `ui.installPlugin` is given approve nothing: it asks all the /// same, and what OK would approve comes from the manifest. A module with nothing to approve /// installs without either.