Plug-ins: commands placed after either label of a switching item keep their order

A placed command's spot is now the matched item's own label rather than the
label its `after` names, so commands whose `after` names the two labels of
one Show/Hide item (Show Bounding Box and Hide Bounding Box) share one spot
and keep plug-in id order and then manifest order. The parity line now says
a live effect whose commands are all placed elsewhere is a single item in
Effect › Plug-ins.
This commit is contained in:
dotCooCoo committed 2026-11-22 07:10:11 -08:00
1 parent 57be8ca36f
commit 2eef47e7e2
3 files changed
+42 -14

No files matched your search

+16 -13
View File
@@ -92,11 +92,11 @@ pub fn place_commands(tree: &mut [(&'static str, Vec<Item>)]) {
continue;
}
// An `after` that names no built-in item of the menu means the end of it, as no `after` does.
let after = place
.after
.as_deref()
.map(|a| anchor_key(a).to_string())
.filter(|a| menu_at(tree, place.path).is_some_and(|menu| menu.iter().any(|it| is_anchor(it, a))));
// The spot is the item's own label, so both labels of an item that switches are one spot.
let after = place.after.as_deref().and_then(|a| {
let menu = menu_at(tree, place.path)?;
menu.iter().find(|it| is_anchor(it, anchor_key(a))).and_then(own_key).map(str::to_string)
});
let id = registry::intern(&vectorcraft_engine::cmd::plugin::command_id(&m.id, &c.id));
let item = Item::Cmd(label(&c.menu_label(&m.name), !c.params.is_empty()), id, Value::Null);
match spots.iter_mut().find(|s| s.0 == place.path && s.1 == after) {
@@ -123,7 +123,7 @@ pub fn place_commands(tree: &mut [(&'static str, Vec<Item>)]) {
}
for (path, after, items) in spots {
let Some(menu) = menu_at(tree, path) else { continue };
let at = after.and_then(|a| menu.iter().position(|it| is_anchor(it, &a))).map_or(menu.len(), |i| i + 1);
let at = after.and_then(|a| menu.iter().position(|it| own_key(it) == Some(a.as_str()))).map_or(menu.len(), |i| i + 1);
menu.splice(at..at, items);
}
}
@@ -137,14 +137,17 @@ fn anchor_key(label: &str) -> &str {
/// [`crate::menus::DYNAMIC_LABELS`] matches by the label of either of its states
/// ([`vectorcraft_engine::cmd::plugin::other_state`]). Items that list a plug-in are never an anchor.
fn is_anchor(it: &Item, key: &str) -> bool {
let other = |l: &str| crate::menus::DYNAMIC_LABELS.contains(&l) && vectorcraft_engine::cmd::plugin::other_state(l).is_some_and(|o| o == key);
own_key(it).is_some_and(|own| own == key || matches!(it, Item::Cmd(l, _, _) if other(l)))
}
/// The label of `it` as [`anchor_key`] reads it, when `it` is a built-in item or submenu that can be
/// an anchor; `None` for an item that lists a plug-in.
fn own_key(it: &Item) -> Option<&str> {
match it {
Item::Cmd(l, id, p) => {
let toggles = crate::menus::DYNAMIC_LABELS.contains(l);
let other = || vectorcraft_engine::cmd::plugin::other_state(l).is_some_and(|o| o == key);
!crate::menus::lists_plugin(id, p) && (anchor_key(l) == key || toggles && other())
}
Item::Sub(l, children) => !crate::menus::holds_plugin_commands(children) && anchor_key(l) == key,
_ => false,
Item::Cmd(l, id, p) if !crate::menus::lists_plugin(id, p) => Some(anchor_key(l)),
Item::Sub(l, children) if !crate::menus::holds_plugin_commands(children) => Some(anchor_key(l)),
_ => None,
}
}
+25
View File
@@ -695,6 +695,31 @@ fn a_plugin_command_is_placed_in_the_menu_its_manifest_names() {
assert!(crate::shortcut_editor::entries().iter().all(|e| e.key != low(bee)));
}
/// Commands placed after an item that switches between two labels are one spot whichever label
/// their `after` names: they keep manifest order within a plug-in and plug-in id order across
/// plug-ins.
#[test]
fn both_labels_of_a_switching_item_are_one_spot() {
let mut app = app();
let (ape, bat) = ("test.ui.place.ape", "test.ui.place.bat");
let command = vectorcraft_engine::cmd::plugin::command_id;
let ape_commands = r#"[{"id":"first","label":"First","menu":{"path":["View"],"after":"Hide Bounding Box"}},
{"id":"second","label":"Second","menu":{"path":["View"],"after":"Show Bounding Box"}}]"#;
let bat_commands = r#"[{"id":"third","label":"Third","menu":{"path":["View"],"after":"Hide Bounding Box"}}]"#;
// Bat is installed first; Ape's id sorts first.
app.run("plugin.install", json!({"dataBase64": placing_plugin(bat, "Bat", bat_commands)})).unwrap();
app.run("plugin.install", json!({"dataBase64": placing_plugin(ape, "Ape", ape_commands)})).unwrap();
let entries = menus::menu_entries(&app);
let view: Vec<&menus::MenuEntry> = entries.iter().filter(|e| e.path == ["View"]).collect();
let toggle = view.iter().position(|e| e.command.as_deref() == Some("view.boundingBox")).expect("Hide Bounding Box is listed");
let after: Vec<Option<String>> = (1..=3).map(|i| view.get(toggle + i).and_then(|e| e.command.clone())).collect();
assert_eq!(after, [Some(command(ape, "first")), Some(command(ape, "second")), Some(command(bat, "third"))]);
for id in [ape, bat] {
app.run("plugin.remove", json!({"id": id})).unwrap();
}
}
/// A live effect whose commands are all placed elsewhere is a single item in Effect › Plug-ins. A
/// filter with the same name placing a command with the same label at the same spot keeps it in its
/// own submenu, so the menu shows that label once. Replaced by a module whose command has no
+1 -1
View File
@@ -2673,7 +2673,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **A plug-in with no permissions ends its id's grant (G17):** installing a module that lists no permissions under a granted id forgets the grant, in the process and in `grants.json`, so the formerly approved bytes need a new approval. Attaching a `Plug-ins` folder whose module for that id lists no permissions forgets it too, and plug-in folders forget the process's grant. A refused install leaves the grant. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_safe_mode.rs`. Scores and hours unchanged.
- **A grant that can't be forgotten stops counting in the whole process (G17):** when such a grant can't be removed from `grants.json`, no session in the process that uses the same `Plug-ins` folder, by any path to it, counts it for `plugin.inspect`, `plugin.install` or loading plug-ins, until `grants.json` can be written for that plug-in; another process on the folder reads `grants.json` as it is. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
- **Plug-in commands (G17):** a filter or live effect may declare up to 32 `commands` (`{id, label, params?}`); each is the command `plugin.<id>.<command>` while the plug-in is installed, in a submenu named after the plug-in under Object › Plug-ins (Effect › Plug-ins for a live effect) unless its manifest places it in another menu, with its label escaped. Commands are recorded in actions, listed in Keyboard Shortcuts for the user to give a shortcut, and run through `run` and MCP with their parameters checked first (a command with parameters opens a dialog from its menu item or shortcut). A run uses the plug-in's permissions (a live effect with commands may also hold `doc.write` and `state`, and gets them without a `permissions` list), is one undo step named after the command, and on failure (a trap or an exhausted instruction budget) leaves the document and the undo history as they were with an error naming the plug-in and the command. For a command and for `plugin.run`, an `ids` that is not a list of object ids is an error rather than the selection. A malformed entry is refused by name when the module is installed. Regressions: `crates/plugins/src/manifest.rs`, `crates/plugins/src/permissions.rs`, `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_fuzz.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
- **Plug-in commands in other menus (G17):** at plug-in API level 2 a command's `menu` (`{path, after?}`) lists it in one of 14 menus of Edit, Object, Type, Select, Effect and View (never File, Window, Help, the application menu or a submenu that lists files, fonts, panels or plug-ins), right after the built-in item `after` names or at the end of the menu, with the plug-in's name in parentheses after its label. Keyboard Shortcuts, the command palette and `command_list` list it under that menu, and `plugin.list` gives its `menu`. Commands of several plug-ins at one spot keep plug-in id order; a plug-in whose commands are all placed elsewhere is a single item in Object › Plug-ins. A command whose label with the plug-in's name reads like a built-in item or submenu of that menu, or like a command a plug-in with a lower id places there, stays in its plug-in's submenu. Any other `menu` is refused by command when the module is installed; at API level 1 the key is still ignored. VectorCraft's own rule. Regressions: `crates/plugins/src/manifest.rs`, `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_fuzz.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
- **Plug-in commands in other menus (G17):** at plug-in API level 2 a command's `menu` (`{path, after?}`) lists it in one of 14 menus of Edit, Object, Type, Select, Effect and View (never File, Window, Help, the application menu or a submenu that lists files, fonts, panels or plug-ins), right after the built-in item `after` names or at the end of the menu, with the plug-in's name in parentheses after its label. Keyboard Shortcuts, the command palette and `command_list` list it under that menu, and `plugin.list` gives its `menu`. Commands at one spot keep plug-in id order and then manifest order; a filter whose commands are all placed elsewhere is a single item in Object › Plug-ins, and such a live effect is a single item in Effect › Plug-ins. A command whose label with the plug-in's name reads like a built-in item or submenu of that menu, or like a command a plug-in with a lower id places there, stays in its plug-in's submenu. Any other `menu` is refused by command when the module is installed; at API level 1 the key is still ignored. VectorCraft's own rule. Regressions: `crates/plugins/src/manifest.rs`, `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_fuzz.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
- **Filter plug-ins call commands (G17, #2186):** a filter at plug-in API level 2 with the `commands` permission names the commands it may run in its manifest's `commandAllowlist` and runs them with `env.vc_call`, reading each result with `env.vc_call_result`. Each call sees what the calls before it changed; the calls and the filter's output are one undo step, and a run that fails, is canceled or makes a call that fails leaves every document, its selection and its history as they were. Commands that read or write files, use the clipboard, change preferences or the view, run scripts, actions or plug-ins, switch documents or undo are never called, and a manifest that lists one is refused when the module is installed. A command counts as taking a file or folder when its params description or schema names a file key as a param; a word in the description's prose or result does not count. Each exemption for a key that names part of the document names a param its command takes, which `every_command_is_sorted` checks, and Image Trace's path fidelity setting (`params.paths`, `savedPreset.paths`) is exempt only inside those settings. The install dialog lists the allowed commands. A run makes at most 1,000 calls, and each call costs 10,000 instructions of its budget. Regressions: `crates/plugins/tests/call.rs`, `crates/engine/tests/plugin_call.rs`, `crates/engine/src/cmd/plugin_call.rs`. Scores and hours unchanged.
- **The command sweep sends file and folder params into its temp folder by the command catalog:** the sweeps in `crates/engine/tests/command_sweep.rs` take each command's file and folder keys from the catalog (`cmd::location_keys`, the same key list the plug-in call rules use, less the keys that name part of the document in a command), read every key a params description names (`{path | name …}`, `{folder? (…)}` included) and its schema's params, and send every string under such a key, in arrays and in objects inside them (`paths: [{ids, path}]`), as a location in the temp folder, so a command added later is swept and checked without editing the sweep. `diffPath` counts as a file key, and Slice Options' `url` and Export for Screens' `folders` do not. Regressions: `sweep_cases_name_files_only_inside_the_temp_folder` and `sweep_cases_send_the_file_keys_of_the_command_catalog` in `command_sweep`, `location_keys_come_from_the_command_catalog` in `cmd::plugin_call`. Scores and hours unchanged.
- **A drag ended by a command with Real-time Drawing off:** when Undo, Redo, a filter that calls commands or a plug-in command that calls commands ends a drag whose preview Real-time Drawing off has not applied yet, the preview is applied first and kept as an undo step of its own, as releasing the drag keeps it; a preview that fails cancels the drag. The filter or plug-in command is then given the objects where the drag left them. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/engine/src/tests/prefs.rs`. Scores and hours unchanged.