From 671cdb3c5b5df80807e37ded3aa320c1eed39408 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Sun, 29 Nov 2026 07:02:37 +0000 Subject: [PATCH] Layers: close the R + click list when the document changes --- crates/ui-egui/src/layer_pick_list.rs | 10 +++++++--- crates/ui-egui/tests/it/layers_panel.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/layer_pick_list.rs b/crates/ui-egui/src/layer_pick_list.rs index 39558758..ab0f37c9 100644 --- a/crates/ui-egui/src/layer_pick_list.rs +++ b/crates/ui-egui/src/layer_pick_list.rs @@ -46,6 +46,8 @@ pub struct LayerPickList { bounds: Rect, /// The layers there, top first, each with the channels it changes there rows: Vec<(LayerId, Vec)>, + /// The document revision the rows were read at: any change, or another project, closes the list + revision: u64, /// The list's first frame: its top row takes the keyboard focus opening: bool, /// Closed by a press outside it: until every button is up, that press neither paints nor reopens it @@ -59,7 +61,9 @@ type HoverLabel = ((usize, (u32, u32), u64, ViewMode), String); pub(crate) fn click(app: &mut TextureCraftApp, at: Pos2, point: Vec2, bounds: Rect) { let viewport = app.session.viewport; match app.session.layers_under(point, viewport) { - Ok((_, rows)) if rows.len() > 1 => app.layer_pick_list = Some(LayerPickList { at, point, bounds, rows, opening: true, closing: false }), + Ok((_, rows)) if rows.len() > 1 => { + app.layer_pick_list = Some(LayerPickList { at, point, bounds, rows, revision: app.session.revision, opening: true, closing: false }); + } _ => { app.run("layer.pickAt", json!({"x": point.x, "y": point.y, "viewport": [viewport.x, viewport.y]})); } @@ -99,13 +103,13 @@ fn area_id() -> egui::Id { egui::Id::unique("layer_pick_list") } -/// Draws the open list; a row click selects its layer, Esc or a press outside closes it +/// Draws the open list; a row click selects its layer; Esc, a press outside or a document change closes it pub(crate) fn show(app: &mut TextureCraftApp, ctx: &egui::Context) { let (any_down, pressed_at, escape) = ctx.input(|input| (input.pointer.any_down(), input.pointer.press_origin().filter(|_| input.pointer.any_pressed()), input.key_pressed(Key::Escape))); let shown = ctx.memory(|memory| memory.area_rect(area_id())); match &mut app.layer_pick_list { - Some(_) if app.ui.mode != Mode::Painting || escape => app.layer_pick_list = None, + Some(list) if app.ui.mode != Mode::Painting || escape || list.revision != app.session.revision => app.layer_pick_list = None, Some(list) if list.closing => { if !any_down { app.layer_pick_list = None; diff --git a/crates/ui-egui/tests/it/layers_panel.rs b/crates/ui-egui/tests/it/layers_panel.rs index fee74407..7efe5ba0 100644 --- a/crates/ui-egui/tests/it/layers_panel.rs +++ b/crates/ui-egui/tests/it/layers_panel.rs @@ -896,6 +896,19 @@ fn the_layer_pick_list_takes_escape_and_its_closing_press_before_an_armed_point_ assert!(armed(&h)); } +/// The list names layers of the stack it was opened on: an edit, an undo or another project closes it +#[test] +fn the_layer_pick_list_closes_when_the_document_changes() { + let (mut h, _) = harness(); + two_fills(&mut h); + open_pick_list(&mut h); + + execute(&mut h.state_mut().session, "edit.undo", &Value::Null).unwrap(); + h.run_steps(SETTLE_FRAMES); + + assert!(h.state().layer_pick_list.is_none()); +} + /// In the split view, a press on the 2D view that closes the list paints nothing there #[test] fn a_press_on_the_2d_view_that_closes_the_layer_pick_list_does_not_paint() {