From b02cd3e905cd6edcc175d7b9cdfec6f24c352091 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 25 Nov 2026 13:22:15 +0000 Subject: [PATCH] A field being edited is one Tab stop --- crates/ui-egui/src/a11y.rs | 15 +++------------ crates/ui-egui/src/field_tests.rs | 8 ++++++++ crates/ui-egui/src/panels/typography/spacing.rs | 2 +- crates/ui-egui/src/widgets.rs | 14 ++++++++++---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/a11y.rs b/crates/ui-egui/src/a11y.rs index ac3562b17..c41417c5b 100644 --- a/crates/ui-egui/src/a11y.rs +++ b/crates/ui-egui/src/a11y.rs @@ -597,8 +597,7 @@ fn focus(app: &mut FigApp, ctx: &Context, id: Id) { ctx.request_repaint(); } -/// The toolbar's arrows: the next or previous control in the region, -/// wrapping. Going back from a field being edited skips the field it is part of. +/// The toolbar's arrows: the next or previous control in the region, wrapping. fn step_within(app: &mut FigApp, ctx: &Context, region: Region, step: i32) { let list = focusables(ctx, &app.ui.nav, region); let n = list.len() as i32; @@ -614,17 +613,9 @@ fn step_within(app: &mut FigApp, ctx: &Context, region: Region, step: i32) { } return; }; - let here = list.get(cur).map(|w| w.1.center()); - let mut i = cur as i32; - for _ in 0..n { - i = (i + step.signum()).rem_euclid(n); - let Some((id, rect)) = list.get(i as usize) else { break }; - // The control a focused field editor sits in. - if here.is_some_and(|c| rect.contains(c)) && i as usize != cur { - continue; - } + let next = (cur as i32 + step.signum()).rem_euclid(n); + if let Some((id, _)) = list.get(next as usize) { focus(app, ctx, *id); - return; } } diff --git a/crates/ui-egui/src/field_tests.rs b/crates/ui-egui/src/field_tests.rs index 9a22f7e89..29d70d21b 100644 --- a/crates/ui-egui/src/field_tests.rs +++ b/crates/ui-egui/src/field_tests.rs @@ -554,6 +554,14 @@ fn arithmetic_commits_tab_moves_on_and_escape_restores() { // With the keyboard on a field and nothing typed, the arrows step it. key(&mut u, Key::ArrowUp, Modifiers::NONE); assert_eq!(geom(&u, a).0, 78.0); + // An editor opened from the keyboard is the same one Tab stop in both directions. + for (first, mods) in [("X", Modifiers::NONE), ("Y", Modifiers::SHIFT)] { + assert_eq!(focused_name(&u.ctx), first); + key(&mut u, Key::Enter, Modifiers::NONE); + assert!(u.ctx.text_edit_focused(), "Enter opens the editor of {first}"); + key(&mut u, Key::Tab, mods); + assert_eq!(focused_name(&u.ctx), if first == "X" { "Y" } else { "X" }, "one Tab from the editor of {first}"); + } } /// Answers a Save as dialog with `path`, once, and counts the dialogs asked for. diff --git a/crates/ui-egui/src/panels/typography/spacing.rs b/crates/ui-egui/src/panels/typography/spacing.rs index 2adc119df..0dff4aecc 100644 --- a/crates/ui-egui/src/panels/typography/spacing.rs +++ b/crates/ui-egui/src/panels/typography/spacing.rs @@ -97,7 +97,7 @@ fn lead_field(ui: &mut Ui, id: Id, glyph: LeadGlyph, value: &str, width: f32, ti let text_rect = Rect::from_min_max(pos2(lead.max.x, rect.min.y), rect.max); let editing_id = id.with("editing"); let mut editing: Option = ui.data(|d| d.get_temp(editing_id)); - let resp = ui.interact(rect, id.with("click"), Sense::click()).on_hover_text(tip); + let resp = ui.interact(rect, id.with("click"), crate::widgets::field_sense(editing.is_some())).on_hover_text(tip); crate::a11y::text(&resp, tip, value); ui.painter().rect_filled(rect, CornerRadius::same(5), t.field); if editing.is_some() { diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index cdd6684af..d29d8f7ec 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -334,8 +334,8 @@ fn number_field_impl( let alt_now = ui.input(|i| i.modifiers.alt); let scrubbing_id = id.with("altscrub"); let scrubbing = ui.data(|d| d.get_temp::(scrubbing_id)).unwrap_or(false); - let field_sense = if editing.is_none() && (alt_now || scrubbing) { Sense::click_and_drag() } else { Sense::click() }; - let field_resp = ui.interact(edit_rect, field_id, field_sense); + let sense = if editing.is_none() && (alt_now || scrubbing) { Sense::click_and_drag() } else { field_sense(editing.is_some()) }; + let field_resp = ui.interact(edit_rect, field_id, sense); let alt_scrub = editing.is_none() && if field_resp.drag_started() { alt_now } else { scrubbing }; ui.data_mut(|d| d.insert_temp(scrubbing_id, alt_scrub && field_resp.dragged() && !field_resp.drag_stopped())); a11y::number(&field_resp, lead.name(), value, suffix, empty.text()); @@ -684,7 +684,7 @@ fn text_field_in(ui: &mut Ui, id: Id, value: &str, rect: Rect, placeholder: &str let t = Tokens::get(ui.ctx()); let editing_id = id.with("editing"); let mut editing: Option = ui.data(|d| d.get_temp(editing_id)); - let resp = ui.interact(rect, id.with("click"), Sense::click()); + let resp = ui.interact(rect, id.with("click"), field_sense(editing.is_some())); let shown = if secret { std::borrow::Cow::Owned("•".repeat(value.chars().count())) } else { std::borrow::Cow::Borrowed(value) }; a11y::text(&resp, name, &shown); ui.painter().rect_filled(rect, CornerRadius::same(5), t.field); @@ -784,6 +784,12 @@ pub fn text_input(ui: &mut Ui, id: Id, text: &mut String, width: f32, hint: &str r } +/// What a field that opens an editor on a click senses itself. While the editor is open, the +/// editor is the field's one Tab stop. +pub(crate) fn field_sense(editing: bool) -> Sense { + if editing { Sense::CLICK } else { Sense::click() } +} + /// Focus for a field's editor that appears on the click that starts editing: egui takes focus /// away from a widget a click lands outside of, and a widget that is new this frame isn't under /// the pointer yet, so the focus is asked for again once it exists. @@ -1418,7 +1424,7 @@ pub fn text_field_inline(ui: &mut Ui, id: Id, value: &str, rect: Rect, font: egu let buf_id = id.with("buf"); let focused = ui.memory(|m| m.has_focus(te_id)); let mut buf: Option = ui.data(|d| d.get_temp(buf_id)); - let resp = ui.interact(rect, id.with("click"), Sense::click()); + let resp = ui.interact(rect, id.with("click"), field_sense(buf.is_some() || focused)); a11y::text(&resp, tr("Name"), value); let started = buf.is_none() && (focused || resp.clicked()); if started {