diff --git a/crates/ui-contract/src/runtime/egui/access.rs b/crates/ui-contract/src/runtime/egui/access.rs index 949eaae58..8bc756366 100644 --- a/crates/ui-contract/src/runtime/egui/access.rs +++ b/crates/ui-contract/src/runtime/egui/access.rs @@ -194,7 +194,7 @@ fn focused_node_key(viewport: ViewportId) -> Id { /// of a list that holds focus, else the focused component's own; `None` when nothing holds focus. pub fn focused_node(ctx: &Context) -> Option { let viewport = pass::current_viewport(ctx); - ctx.data(|data| data.get_temp::(focused_node_key(viewport))).map(|node| node.0) + memory::peek_copy::(ctx, focused_node_key(viewport)).map(|node| node.0) } /// The runtime's nodes of a pass in the order it emitted them: the first time each node was reported as a child or @@ -312,12 +312,10 @@ pub(crate) fn order_children(ctx: &Context) { ctx.set_accesskit_focus(owner); } let focused = widget.map(|widget| emitted.focus.or(folded).unwrap_or(widget)); - ctx.data_mut(|data| match focused { - Some(node) => { - data.insert_temp(focused_node_key(viewport), FocusedNode(node)); - } - None => data.remove::(focused_node_key(viewport)), - }); + match focused { + Some(node) => memory::put(ctx, focused_node_key(viewport), FocusedNode(node)), + None => drop(memory::take::(ctx, focused_node_key(viewport))), + } hide_behind_modal(ctx, viewport, &emitted.written); for parent in emitted.written { ctx.accesskit_node_builder(parent, |node| { diff --git a/crates/ui-contract/src/testing/host_key_trials.rs b/crates/ui-contract/src/testing/host_key_trials.rs index bf7681f4c..a3e146115 100644 --- a/crates/ui-contract/src/testing/host_key_trials.rs +++ b/crates/ui-contract/src/testing/host_key_trials.rs @@ -533,6 +533,7 @@ fn navigation_keys_with_canvas(focus_field: bool) -> (Vec, bool) { } reached.borrow_mut().clear(); let caret = |frames: &Frames| { + // design: allow[contract/egui-widget](the trial reads the caret of the app's own egui TextEdit, which is what it checks) egui::TextEdit::load_state(&frames.ctx, field()).and_then(|state| state.cursor.char_range()).map(|range| range.primary.index) }; let at_end = caret(&frames); diff --git a/design/exceptions/craft-ui-contract/testing.toml b/design/exceptions/craft-ui-contract/testing.toml index 05d73cc64..d3eb38de8 100644 --- a/design/exceptions/craft-ui-contract/testing.toml +++ b/design/exceptions/craft-ui-contract/testing.toml @@ -15,3 +15,11 @@ rule = "probe/exempt/text-size" path = "crates/ui-contract/src/testing/face_runs.rs" reason = "The 4,000-point run is drawn at the font atlas's cap, which is in device pixels: at twice the scale the cap, and the card, are half as many points." count = 1 + +[[exception]] +name = "host-key-trial-app-text-edit" +kind = "marker" +rule = "contract/egui-widget" +path = "crates/ui-contract/src/testing/host_key_trials.rs" +reason = "The trial reads the caret of the app's own egui TextEdit, which is what it checks." +count = 1