From c3a6fbf2505ae9e836f276ed931c52981033095b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 27 Oct 2026 21:06:28 -0700 Subject: [PATCH] Appearance: Add New Fill and Add New Stroke with an empty ids list run nothing without a selection Called with `"ids": []` and nothing selected or targeted, the two commands ran and put "select objects or give ids" in the status bar. An empty ids list now counts as no ids, so the commands run nothing, as they do when ids is left out. A non-empty ids list still adds to those objects. --- crates/ui-egui/src/menus/invoke.rs | 6 +++++- crates/ui-egui/src/menus/state.rs | 5 +++-- crates/ui-egui/src/panels/tests_appearance.rs | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index a0e7acae6..ee8e4c593 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -109,7 +109,11 @@ pub fn invoke(app: &mut VectorcraftApp, id: &str, p: Value) { if waits_for_ime(app, id) { return; } - if SUBJECT_COMMANDS.contains(&id) && p.get("ids").is_none() && p.get("id").is_none() && !has_subject(app) { + if SUBJECT_COMMANDS.contains(&id) + && p.get("ids").is_none_or(|ids| ids.as_array().is_some_and(Vec::is_empty)) + && p.get("id").is_none() + && !has_subject(app) + { return; } // Params first: some dialogs' fields take a look through the session (Move's last move). diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index 0c6bb8206..cffd3747d 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -156,8 +156,9 @@ pub(crate) fn waits_for_ime(app: &VectorcraftApp, id: &str) -> bool { } /// Engine commands that take `ids` and otherwise act on the Appearance panel's subject (the -/// targeted layer, group or object, else the selection). Without `ids` and without a subject they -/// are off, as the panel's buttons are: in menus, in the command palette and on their keys. +/// targeted layer, group or object, else the selection). Without `ids` (or with an empty list) and +/// without a subject they are off, as the panel's buttons are: in menus, in the command palette and +/// on their keys. pub(super) const SUBJECT_COMMANDS: [&str; 2] = ["appearance.addFill", "appearance.addStroke"]; /// Is there an Appearance panel subject: a targeted layer, group or object, or a selected one? diff --git a/crates/ui-egui/src/panels/tests_appearance.rs b/crates/ui-egui/src/panels/tests_appearance.rs index ed3e26892..82c2b9f20 100644 --- a/crates/ui-egui/src/panels/tests_appearance.rs +++ b/crates/ui-egui/src/panels/tests_appearance.rs @@ -203,8 +203,8 @@ fn cmd_slash_adds_a_fill_and_cmd_alt_slash_a_stroke_as_the_panel_buttons_do() { } /// With nothing selected, Add New Fill and Add New Stroke are off in menus and the command palette -/// as the Appearance panel's buttons are, and their keys run nothing (no error in the status bar). -/// Given ids, they still add to those objects. +/// as the Appearance panel's buttons are, and their keys run nothing (no error in the status bar); +/// an empty `ids` list runs nothing either. Given ids, they still add to those objects. #[test] fn add_new_fill_and_stroke_are_off_without_a_selection() { let mut app = app_with_rect(); @@ -223,6 +223,8 @@ fn add_new_fill_and_stroke_are_off_without_a_selection() { out.textures_delta.clear(); crate::menus::invoke(&mut app, id, json!({})); assert_eq!((items(&app), app.ui.status.as_str()), (before, ""), "{id} ran nothing"); + crate::menus::invoke(&mut app, id, json!({"ids": []})); + assert_eq!((items(&app), app.ui.status.as_str()), (before, ""), "{id} with no ids ran nothing"); } crate::menus::invoke(&mut app, "appearance.addFill", json!({"ids": [rect.0]})); assert_eq!((items(&app), app.ui.status.as_str()), (before + 1, ""), "given ids, it adds a fill");