From 5b98ed3b7d9b4601716bd817fe6600757965642e Mon Sep 17 00:00:00 2001 From: Francisco Herrera <14956584+alosslessdev@users.noreply.github.com> Date: Sat, 7 Nov 2026 18:25:32 -0500 Subject: [PATCH] Layers: Delete clears the selection after the last row is deleted (#5870) --- crates/ui-egui/src/panels/layers.rs | 6 ++++-- crates/ui-egui/src/panels/tests_appearance.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 65f7c6bc3..42bd09a4a 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -361,9 +361,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { // Keyboard: Delete removes the highlighted rows while the panel has the keyboard (a row was // clicked last, not the canvas). // The panel keeps it while it is drawn ([`super::has_row_keys`]); the app's shortcuts leave - // Delete and Backspace to it meanwhile ([`super::rows_take_delete`]). + // Delete and Backspace to it meanwhile ([`super::rows_take_delete`]). With no highlighted rows + // left (the last one was deleted) the panel gives the keys back, so Delete clears the selected + // art again instead of doing nothing. let pressed_outside = ui.input(|i| i.pointer.any_pressed() && i.pointer.interact_pos().is_some_and(|p| !list_rect.contains(p))); - let focus = super::has_row_keys(ui.ctx(), ROW_KEYS) && !pressed_outside; + let focus = super::has_row_keys(ui.ctx(), ROW_KEYS) && !pressed_outside && !view.rows.is_empty(); super::set_row_keys(ui.ctx(), ROW_KEYS, focus); if focus && !view.rows.is_empty() diff --git a/crates/ui-egui/src/panels/tests_appearance.rs b/crates/ui-egui/src/panels/tests_appearance.rs index ba4eebdda..b7ed12486 100644 --- a/crates/ui-egui/src/panels/tests_appearance.rs +++ b/crates/ui-egui/src/panels/tests_appearance.rs @@ -1481,6 +1481,25 @@ fn after_a_row_click_delete_reaches_the_layers_panel_not_edit_clear() { assert!(d.node(rect).is_some(), "the rectangle on Layer 1 stays"); } +/// After Delete removed the last highlighted Layers row, the panel has nothing left to delete: the +/// next Delete must go back to the app and clear the selected object, not be swallowed by the +/// panel's row keys. +#[test] +fn delete_after_the_last_highlighted_layer_row_is_deleted_clears_the_selection() { + let ctx = drop_ctx(); + let mut app = app_with_rect(); + run(&mut app, "layer.new", json!({})); + let rect = first_selected(&app).unwrap().id; + let texts = frame_events(&ctx, &mut app, vec![], boxed_layers); + let row = text_rect(&texts, "Layer 2").center(); + app_click(&ctx, &mut app, row, boxed_layers); + app_key(&ctx, &mut app, egui::Key::Delete, boxed_layers); + assert_eq!(app.session.active().unwrap().doc.layers.len(), 1, "Layer 2 is deleted"); + assert!(app.session.active().unwrap().selection.contains(rect), "the rectangle stays selected"); + app_key(&ctx, &mut app, egui::Key::Delete, boxed_layers); + assert!(app.session.active().unwrap().doc.node(rect).is_none(), "Delete clears the selected object once the panel has no rows"); +} + /// A tool that claims Delete and Backspace (the Artboard tool's active artboard) leaves them to a /// clicked Layers row. #[test]