Layers: Delete clears the selection after the last row is deleted (#5870)

This commit is contained in:
Francisco Herrera
2026-11-09 02:03:07 +07:00
committed by bflatastic
parent d8d3f43642
commit 5b98ed3b7d
2 changed files with 23 additions and 2 deletions
+4 -2
View File
@@ -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()
@@ -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]