diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index a03e9e8538..7e894b5d5a 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -1160,7 +1160,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, or in isolation mode with one of the rows outside the isolated art, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. In isolation mode a row outside the isolated art is an error and nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 6d950c882b..9d793c2966 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -1161,7 +1161,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.layerDelete", "Delete Selection", "", - "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, or in isolation mode with one of the rows outside the isolated art, nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", + "{ids?|id?, doc?, confirmed?: bool} Delete Selection as the Layers panel runs it (its trash button, rows dropped on the trash, its menu, Delete and Backspace), on the rows layer.delete takes (default: the highlighted rows, else the current layer; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted). When a layer or sublayer among them holds art (an object other than a guide; hidden, locked and nested objects count) it asks first: dialog `confirm` with `message`; OK deletes those rows by id with layer.delete (one undo step), Cancel keeps them. OK runs ui.layerDelete again with the rows, `doc` (the document's uid) and `confirmed: true`: with another document active then, nothing is deleted. In isolation mode a row outside the isolated art is an error and nothing is deleted. Other rows (an empty layer, groups and objects alone) and rows layer.delete refuses go to layer.delete at once → layer.delete's {deleted}, or null while the question is open", ), ( "ui.rename", diff --git a/crates/ui-egui/src/panels/layers/controls.rs b/crates/ui-egui/src/panels/layers/controls.rs index c01594a329..31f07c4929 100644 --- a/crates/ui-egui/src/panels/layers/controls.rs +++ b/crates/ui-egui/src/panels/layers/controls.rs @@ -307,8 +307,8 @@ fn save_selection_menu(app: &mut VectorcraftApp, ui: &mut Ui) { /// `layer.delete` takes (default: the highlighted rows, else the current layer; in isolation mode a /// current layer outside the isolated art is an error). When a layer or sublayer among them holds art (an object other than a /// guide, hidden, locked and nested ones included), it asks first: OK deletes those rows, by id, in -/// the same document (`doc`, its uid, with `confirmed`); with another document active then, or in -/// isolation mode with one of them outside the isolated art, nothing is deleted. Other rows, and rows `layer.delete` refuses (an unknown id, every top-level layer), +/// the same document (`doc`, its uid, with `confirmed`); with another document active then, nothing +/// is deleted. In isolation mode a row outside the isolated art is an error, and nothing is deleted. Other rows, and rows `layer.delete` refuses (an unknown id, every top-level layer), /// go to `layer.delete` at once. → `layer.delete`'s result, or null while the question is open pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { let confirmed = crate::menus::opt_bool(p, "confirmed")?.unwrap_or(false); @@ -335,12 +335,17 @@ pub fn delete(app: &mut VectorcraftApp, p: &Value) -> Result { Some(if rows.is_empty() { st.current_layer().into_iter().collect() } else { rows }) } }; - // Isolation mode can start while the question is open: OK then deletes nothing when a row it - // asked about is outside the isolated art. - if confirmed && ids.as_ref().is_some_and(|ids| ids.iter().any(|id| !in_isolated_art(st, *id))) { + // Isolation mode can start while rows are dragged to the trash or while the question is open: + // nothing is deleted when a row is outside the isolated art. + if ids.as_ref().is_some_and(|ids| ids.iter().any(|id| !in_isolated_art(st, *id))) { return Err("the object is outside the isolated group".into()); } - let Some(ids) = ids.filter(|_| !confirmed) else { return app.run("layer.delete", Value::Object(rows)) }; + let ids = match ids { + // Confirmed without rows given: the rows the panel lists, not every highlighted row. + Some(ids) if confirmed && rows.is_empty() => return app.run("layer.delete", json!({ "ids": ids.iter().map(|i| i.0).collect::>() })), + Some(ids) if !confirmed => ids, + _ => return app.run("layer.delete", Value::Object(rows)), + }; let listed: HashSet = ids.iter().copied().collect(); let mut roots = vec![]; row_roots(&st.doc.layers, &listed, &mut roots); diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index f24694091a..403515b228 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -988,10 +988,11 @@ fn isolation_keeps_the_panel_menu_to_the_rows_listed() { } /// OK in Delete Selection's question deletes nothing when isolation mode started while it asked and -/// a row it asked about is outside the isolated art. +/// a row it asked about is outside the isolated art, and rows given outside it, as rows dropped on +/// the trash are, are not deleted either. #[test] fn isolation_keeps_a_confirmed_delete_to_the_rows_listed() { - let (mut app, [_, sub, g, ..]) = nested(); + let (mut app, [_, sub, g, _, a, c]) = nested(); let uid = app.session.active().unwrap().uid; app.session.active_mut().unwrap().layer_rows = vec![sub]; assert!(app.run("ui.layerDelete", json!({})).unwrap().is_null(), "it asks first"); @@ -1000,7 +1001,16 @@ fn isolation_keeps_a_confirmed_delete_to_the_rows_listed() { let err = app.run("ui.layerDelete", ok.clone()).unwrap_err(); assert!(err.contains("the object is outside the isolated group"), "{err}"); assert!(app.session.active().unwrap().doc.node(sub).is_some(), "nothing was deleted"); - app.session.execute("object.exitIsolation", &json!({})).unwrap(); + let err = app.run("ui.layerDelete", json!({"ids": [c.0]})).unwrap_err(); + assert!(err.contains("the object is outside the isolated group"), "{err}"); + assert!(app.session.active().unwrap().doc.node(c).is_some(), "the rectangle outside the group stays"); + // OK with no rows given deletes the highlighted rows the panel lists, inside the sublayer. + app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap(); + app.session.active_mut().unwrap().layer_rows = vec![a, c]; + app.run("ui.layerDelete", json!({"doc": uid, "confirmed": true})).unwrap(); + let doc = &app.session.active().unwrap().doc; + assert!(doc.node(a).is_none() && doc.node(c).is_some(), "only the row inside the sublayer is deleted"); + app.session.execute("object.exitIsolation", &json!({"all": true})).unwrap(); app.run("ui.layerDelete", ok).unwrap(); assert!(app.session.active().unwrap().doc.node(sub).is_none()); } diff --git a/docs/mcp.md b/docs/mcp.md index 1c50f93f9f..1640f8d67b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5875,8 +5875,8 @@ and `layerRows`, the rows highlighted in the panel. the selected items and their artwork?"; OK deletes the rows it asked about in that document, one undo step, and Cancel keeps them; an empty layer, a layer with only guides, and groups or objects alone are deleted at once; in isolation mode, with no row highlighted, a current layer outside the isolated art is an error and nothing is deleted, - and OK deletes nothing when isolation mode started while it asked and a row it asked about is outside the isolated - art), + and so is a row outside it, given as `ids` or `id`, dropped on the trash or asked about before isolation mode + started), `layer.locate {id?, layersOnly?}` (highlights the selected object's row, or with several selected the row of the one frontmost in the stacking order, whatever order they were selected in; an `id` locates that object instead; the panel opens the rows around it;