diff --git a/crates/ui-contract/src/runtime/focus.rs b/crates/ui-contract/src/runtime/focus.rs index 405187cd9..a75ce8ea6 100644 --- a/crates/ui-contract/src/runtime/focus.rs +++ b/crates/ui-contract/src/runtime/focus.rs @@ -277,10 +277,14 @@ pub(crate) fn is_canvas_member(ctx: &Context, rec: &StopRec) -> bool { }) } -/// Whether a Tab in `viewport` has nothing to leave and nowhere to go: egui held no focus at the end of its last pass -/// and it registered no focus stop there. Read by the input hook, before the begin hook rotates the registrations. -pub(crate) fn tab_from_nothing(ctx: &Context, viewport: ViewportId) -> bool { - with_viewport(ctx, viewport, |state| state.focus_now.is_none() && state.stops.is_empty()) +/// Whether a bare Tab in `viewport` is egui's own focus move: the window registered no framework stop in its last pass, +/// only stops of the app's own egui widgets (`Stop::host`) if any, which egui's Tab order holds with the app's other +/// widgets; and egui held no focus at the end of that pass, or held it on one of those stops. A framework move would +/// reach the host stops alone. Read by the input hook, before the begin hook rotates the registrations. +pub(crate) fn tab_is_egui_s(ctx: &Context, viewport: ViewportId) -> bool { + with_viewport(ctx, viewport, |state| { + state.stops.iter().all(|rec| rec.stop.host) && state.focus_now.is_none_or(|id| state.stops.iter().any(|rec| rec.stop.root == id)) + }) } /// How many stops the running pass has registered so far. @@ -1004,8 +1008,8 @@ pub(crate) fn begin(ctx: &Context, tab_all_controls: bool, dialog_tab: TabReach) let (acts, announcements) = nav::begin(state, input); (acts, announcements, host_focus) }); - // egui's direction moves focus from the widget it holds, an app's own, or from nothing with a Tab the key stage - // left to egui; never in a pass whose focus the framework moves. + // egui's direction moves focus from the widget it holds, an app's own, or with a Tab the key stage left to egui + // (from nothing or a host stop); never in a pass whose focus the framework moves. if !(host_focus || tab_to_egui) || !acts.is_empty() { egui_focus::clear_directional_focus(ctx); } diff --git a/crates/ui-contract/src/runtime/keys/input.rs b/crates/ui-contract/src/runtime/keys/input.rs index f1f0c09e1..db3f8a949 100644 --- a/crates/ui-contract/src/runtime/keys/input.rs +++ b/crates/ui-contract/src/runtime/keys/input.rs @@ -56,10 +56,12 @@ struct Strip<'a> { /// The edit set whose clipboard events and edit chords stay in egui's input: the focused stop's when it is the /// app's own widget (`host`), else the canvas's with nothing focused (`canvas`). egui_edits: EditSet, - /// egui holds no focus and the window registered no focus stop in its last pass: a framework focus move has - /// nowhere to go, so a bare Tab is egui's. Focus on a component's widget without a stop is focus: egui would take - /// a Tab from it as a move to the next widget it shows, in a later pass. - no_stops: bool, + /// A bare Tab that the focus does not keep is egui's own move (`focus::tab_is_egui_s`): the window registered no + /// framework stop in its last pass, only the app's own widgets' (`Stop::host`) if any, and nothing has the focus or + /// one of those stops has it. egui's Tab order holds those stops and the app's other widgets; a framework move + /// would reach the stops alone. Focus on a component's widget without a stop is focus: egui would take a Tab from + /// it as a move to the next widget it shows, in a later pass. A Tab that toggles the chrome stays the framework's. + egui_tab: bool, /// egui holds a label text selection, which a copy or cut event copies. label_selection: bool, /// A tool host claimed the lone Alt tap: it goes to the claimer on every OS, not to the menu bar. @@ -379,7 +381,7 @@ impl Strip<'_> { PressUse::CanvasSpace } else if (self.foreign && (bare_tab || escape)) || (self.host && escape && !self.press_captured) || canvas_tab || egui_edit { PressUse::Egui - } else if bare_tab && self.no_stops { + } else if bare_tab && self.egui_tab && !self.keeps_tab { PressUse::TabToEgui } else if bare_tab && !self.keeps_tab { PressUse::Tab @@ -442,7 +444,8 @@ impl Strip<'_> { // command with it either. PressUse::Egui => true, PressUse::TabToEgui => { - // egui moves its own focus with it, from nothing focused into the app's own widgets (`focus::begin`). + // egui moves its own focus with it, from nothing focused or a host stop through the app's own widgets + // (`focus::begin`). batch.nav.tab_to_egui = true; true } @@ -535,7 +538,7 @@ enum PressUse { CanvasSpace, /// The app's own widget or popup, or the canvas with nothing focused, reads the key from egui. Egui, - /// A bare Tab egui moves its own focus with. + /// A bare Tab egui moves its own focus with, through the app's own widgets. TabToEgui, /// A bare Tab: a focus move or a chrome toggle, which `take_nav` decides. Tab, @@ -667,7 +670,10 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec; @@ -700,7 +706,7 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec