From 02cdd2517970116f7aa94bc7b39b29dd02610cff Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 18:50:22 +0000 Subject: [PATCH] An AccessKit request on a settled view's node reruns the view A settled memoized view replayed unless a routed intent's target was one of its egui widgets or focus stops. An AccessKit Click on a part with no stop (a tab's close button) goes to the node's owner, a collection row's component, which is neither, so the dock's tab row replayed and nobody read the click. A record notes the owners of the nodes its run registered (Facts::node_owners), and a request routed to one of them runs the view. The documents story's tabs close again. --- crates/ui-contract/src/runtime/keys/nodes.rs | 2 ++ crates/ui-contract/src/runtime/lazy.rs | 2 +- crates/ui-contract/src/runtime/replay.rs | 10 +++++++++ crates/ui-panels/src/docking/stories.rs | 17 +++++++++------ crates/ui-panels/tests/it/dock_group.rs | 22 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/crates/ui-contract/src/runtime/keys/nodes.rs b/crates/ui-contract/src/runtime/keys/nodes.rs index aed007d29..5cb66d531 100644 --- a/crates/ui-contract/src/runtime/keys/nodes.rs +++ b/crates/ui-contract/src/runtime/keys/nodes.rs @@ -11,6 +11,7 @@ pub(crate) fn redirect_node(ctx: &Context, node: Id, owner: Id, part: PartRef) { // Journaled after the `register_node` it amends, so a settled view's replay leaves the row's node with the // collection, as a run does. crate::runtime::replay::journal(ctx, || (node, owner, part), |ctx, &(node, owner, part)| redirect_node(ctx, node, owner, part)); + crate::runtime::replay::note_node_owner(ctx, owner); current(ctx, |stage| { if let Some(entry) = stage.nodes.get_mut(&node_key(node)) { entry.owner = owner; @@ -37,6 +38,7 @@ pub(crate) fn register_node(ctx: &Context, node: Id, owner: Id, part: Option, + /// The components that take the AccessKit requests on the nodes the run registered (`note_node_owner`): a request + /// routed to one of them is routed into the run, though the component is no egui widget (a collection's row). + pub(crate) node_owners: Vec, /// The layout memory entries the run kept (`note_layout_keep`): a replay keeps them (`layout_memory::keep`). pub(crate) layout_keeps: Vec, /// The derived values the run asked for (`note_derived_keep`): a replay keeps them, since it asks for none. @@ -293,6 +296,7 @@ pub(crate) fn close(ctx: &Context, layer: Layer) -> Record { outer.facts.blocked |= open.facts.blocked; outer.facts.discards |= open.facts.discards; outer.facts.owners.extend(open.facts.owners.iter().copied()); + outer.facts.node_owners.extend(open.facts.node_owners.iter().copied()); outer.facts.layout_keeps.extend(open.facts.layout_keeps.iter().copied()); outer.facts.derived_keeps.extend(open.facts.derived_keeps.iter().copied()); outer.facts.wake = min_wake(outer.facts.wake, open.facts.wake); @@ -579,6 +583,12 @@ pub(crate) fn note_derived_keep(ctx: &Context, slot: egui::Id) { with_open(ctx, |facts| facts.derived_keeps.push(slot)); } +/// Notes that `owner` takes the AccessKit requests on a node the running code registered (`keys::register_node`). A +/// replay registers the node again from its journal, which notes it in the records open around the replay. +pub(crate) fn note_node_owner(ctx: &Context, owner: egui::Id) { + with_open(ctx, |facts| facts.node_owners.push(owner)); +} + /// Notes that the memory owner `owner` registered in the running code. pub(crate) fn note_owner(ctx: &Context, owner: egui::Id) { with_open(ctx, |facts| facts.owners.push(owner)); diff --git a/crates/ui-panels/src/docking/stories.rs b/crates/ui-panels/src/docking/stories.rs index 8dc070073..e07ee8e39 100644 --- a/crates/ui-panels/src/docking/stories.rs +++ b/crates/ui-panels/src/docking/stories.rs @@ -120,18 +120,23 @@ fn a_panel_with_a_count_and_a_caption(ui: &mut Ui, _: &mut StoryData) -> StoryOu DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).show(ui, |_, _| ()).output.into() } -/// A group whose Timeline lists its open compositions as tabs after the panel tabs, each with its label colour; the -/// shown composition's tab is selected while the Timeline shows, and a pick shows another. +/// A group whose Timeline lists its open compositions as tabs after the panel tabs, each with its label colour and a +/// close button; the shown composition's tab is selected while the Timeline shows, a pick shows another and a close +/// closes it. #[story(DockGroup<'static, usize>, covers = [Default])] fn a_panel_with_documents(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let shown = *data.value("shown", 1_u64); - let comp = |id: u64, name: &'static str, color: Option| PanelDocument::new(id, name).swatch(color).shown(id == shown); - let documents = vec![comp(1, "Comp 1", Some(Srgba::rgb(0.8, 0.3, 0.3))), comp(2, "Comp 2", None)]; - let panels = vec![title_of(LAYERS).documents(documents), title_of(CHANNELS)]; - let output = DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).show(ui, |_, _| ()).output; + let open = data.value("open", vec![1_u64, 2]).clone(); + let comp = |id: u64| { + let color = (id == 1).then(|| Srgba::rgb(0.8, 0.3, 0.3)); + PanelDocument::new(id, format!("Comp {id}")).swatch(color).closable(true).shown(id == shown) + }; + let panels = vec![title_of(LAYERS).documents(open.iter().map(|id| comp(*id)).collect()), title_of(CHANNELS)]; + let output = DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).closable().show(ui, |_, _| ()).output; if let Some((_, id)) = output.picked_document { *data.value("shown", 1_u64) = id; } + data.value("open", vec![1_u64, 2]).retain(|id| !output.closed_documents.iter().any(|(_, closed)| closed == id)); output.into() } diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs index af4ef19cb..44240a12a 100644 --- a/crates/ui-panels/tests/it/dock_group.rs +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -330,3 +330,25 @@ fn closable_panel_tabs_shrink_and_close_on_a_middle_click() { assert_eq!(closed.get(), Some(keys[2]), "the middle click closes the tab"); assert_eq!(picked.get(), None, "the middle click does not show the tab first"); } + +// An AccessKit click on a closable tab's close button closes the tab, as a click on it does, though the tab row has +// settled and replays its last run. +#[trial] +fn an_access_click_on_a_settled_tabs_close_button_closes_it() { + use craft_ui::testing::focus::AccessActionKind; + let closed = Rc::new(Cell::new(None::)); + let closes = Rc::clone(&closed); + let panels = vec![PanelTitle::new(PanelKey::new(1), "Color").closable(true), PanelTitle::new(PanelKey::new(2), "Swatches").closable(true)]; + let key = panels[1].key; + let mut fixture = Fixture::new(move |ui| { + let group = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key).closable(); + let out = group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 240.0)), |_, _| ()); + if let Some(key) = out.output.closed.first() { + closes.set(Some(*key)); + } + }); + fixture.idle(4); + let Some(close) = fixture.by_label("Close Swatches") else { panic!("the Swatches tab shows a close button") }; + fixture.access(AccessActionKind::Click, &close).settle(); + assert_eq!(closed.get(), Some(key), "the access click closes the tab"); +}