Merge pull request #4408 from dotCooCoo/fix/appearance-add-keys-empty-ids

Appearance: Add New Fill and Add New Stroke with an empty ids list run nothing without a selection
This commit is contained in:
BFlat
2026-10-29 10:48:07 +07:00
committed by GitHub
3 changed files with 12 additions and 5 deletions
+5 -1
View File
@@ -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).
+3 -2
View File
@@ -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?
@@ -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");