ui-contract: access state through runtime::egui::memory; mark the host-key trial's TextEdit read

This commit is contained in:
aiongg
2026-11-24 19:27:43 +00:00
parent 2b20e152e3
commit 44260259bf
3 changed files with 14 additions and 7 deletions
@@ -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<Id> {
let viewport = pass::current_viewport(ctx);
ctx.data(|data| data.get_temp::<FocusedNode>(focused_node_key(viewport))).map(|node| node.0)
memory::peek_copy::<FocusedNode>(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::<FocusedNode>(focused_node_key(viewport)),
});
match focused {
Some(node) => memory::put(ctx, focused_node_key(viewport), FocusedNode(node)),
None => drop(memory::take::<FocusedNode>(ctx, focused_node_key(viewport))),
}
hide_behind_modal(ctx, viewport, &emitted.written);
for parent in emitted.written {
ctx.accesskit_node_builder(parent, |node| {
@@ -533,6 +533,7 @@ fn navigation_keys_with_canvas(focus_field: bool) -> (Vec<Key>, 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);
@@ -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