diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index d4e22e330..0aa72e557 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -419,11 +419,6 @@ pub(crate) fn run( now, }, ); - // While the text widget takes the pointer it lies over the root and egui hands it the presses there: it stands for - // the root, so the focus service resolves such a press among the root's shapes and the field keeps its focus. - if pointer && focusable { - crate::runtime::pointer::record_widgets(&ctx, ui.layer_id(), id, &[widget], true); - } // Focus that moved to another part of the component leaves the text part like a focus loss: the draft commits. let left_for_part = out.focused && cx.active_part().is_some(); if left_for_part { diff --git a/crates/ui-contract/src/runtime/focus/press.rs b/crates/ui-contract/src/runtime/focus/press.rs index 3ad241c2c..e5ce6b166 100644 --- a/crates/ui-contract/src/runtime/focus/press.rs +++ b/crates/ui-contract/src/runtime/focus/press.rs @@ -15,13 +15,16 @@ pub(crate) struct PressAt { winner: Option>, /// The arena root the winner belongs to. root: Option, + /// The egui widget that takes the press. + target: Option, } pub(crate) fn press_at(ctx: &Context) -> Option { // A press the modal's canvas took moves no key focus: the dialog keeps it. egui_focus::primary_press_origin(ctx).filter(|pos| !sampler::admitted_press(ctx, *pos)).map(|pos| { - let (winner, root) = pointer::press_winner(ctx, pos, pointer::pass_pointer(ctx).press_targets).unzip(); - PressAt { winner, root } + let targets = pointer::pass_pointer(ctx).press_targets; + let (winner, root) = pointer::press_winner(ctx, pos, targets).unzip(); + PressAt { winner, root, target: targets.click } }) } @@ -59,7 +62,10 @@ impl State { /// text part to commit its draft when the press leaves it. pub(super) fn classify_press(&mut self, at: &PressAt) { let winner = at.winner.as_ref(); - let kind = classify_press(winner.map(|winner| winner.sense)); + // A press on the widget that holds the focus (the text of a field in edit) is that widget's own: it keeps the + // focus and the draft. + let on_focused = at.target.is_some() && at.target == self.stop_of_focus().map(|rec| rec.stop.root); + let kind = if on_focused { PressFocus::Keep } else { classify_press(winner.map(|winner| winner.sense)) }; let (owner, part) = winner.map_or((None, None), |winner| (Some(winner.owner), winner.part)); let text_stop = self.stop_of_focus().filter(|stop| stop.stop.text).map(|stop| stop.stop.id); let was_text = text_stop.is_some() && kind.commits_draft();