Access nodes: a collection's redirect of a row's node is journaled, so a settled dock panel's replay keeps the row's node with the collection and an access Focus on a Layers row focuses the rows

This commit is contained in:
aiongg
2026-11-17 03:07:07 +00:00
parent c1cb2df8eb
commit 2970ef8cc0
2 changed files with 21 additions and 5 deletions
+18 -5
View File
@@ -5,6 +5,7 @@ use craft_behavior::{EditEvent, EditHistory, Mixed, SelectionChange};
use craft_layers::ui::mock::FakeLayers;
use craft_layers::ui::panel::{LayerColumn, LayerDrop, LayerPosition, LayerToggle, LayersEvent, LayersPanel};
use craft_layers::ui::tree::{LayerKind, LayerPart, LayerSelection};
use craft_ui::contract::Lazy;
use craft_ui::testing::access::focused_key;
use craft_ui::testing::focus::AccessActionKind;
use craft_ui::testing::{Fixture, Target, pointer, trial};
@@ -247,11 +248,23 @@ fn shift_right_and_left_open_and_close_the_active_layers_effects() {
/// A row's access focus action, as a screen reader or a test driver gives it, puts key focus in the rows with the
/// lead on that row: the access focus lands on the row's node.
/// So does it while the panel is a settled region that replays its last run.
#[trial]
fn a_rows_access_focus_action_leads_the_focused_rows_to_it() {
let (mut fixture, _app) = rig(FakeLayers::sample());
let styled = row(&fixture, "Styled");
fixture.access(AccessActionKind::Focus, &styled).idle(2);
assert!(fixture.focused_stop().is_some(), "the rows hold key focus");
assert_eq!(focused_key(fixture.tree()), styled.node, "the access focus is on the row");
let settled = || {
let app = Rc::new(RefCell::new(App { tree: FakeLayers::sample(), events: Vec::new() }));
let shared = Rc::clone(&app);
let mut fixture = Fixture::new(move |ui| {
Lazy::new("layers", 0.0).settles(true).show(ui, |ui| show(ui, &mut shared.borrow_mut()));
});
fixture.room(PANEL);
fixture.settle();
(fixture, app)
};
for (mut fixture, _app) in [rig(FakeLayers::sample()), settled()] {
let styled = row(&fixture, "Styled");
fixture.access(AccessActionKind::Focus, &styled).idle(2);
assert!(fixture.focused_stop().is_some(), "the rows hold key focus");
assert_eq!(focused_key(fixture.tree()), styled.node, "the access focus is on the row");
}
}
@@ -8,6 +8,9 @@ use egui::{Context, Id};
/// Makes `owner` the receiver of the requests that target the node of `node` (registered by `register_node`) and names
/// `part` as the target: the row of a collection is a node of the row's component, and the collection acts on it.
pub(crate) fn redirect_node(ctx: &Context, node: Id, owner: Id, part: PartRef) {
// Journaled after the `register_node` it amends, so a settled region's replay leaves the row's node with the
// collection, as a run does.
crate::runtime::replay::journal(ctx, || move |ctx: &Context| redirect_node(ctx, node, owner, part));
current(ctx, |stage| {
if let Some(entry) = stage.nodes.get_mut(&node_key(node)) {
entry.owner = owner;