diff --git a/crates/ui-widgets/src/pickers/combo_box.rs b/crates/ui-widgets/src/pickers/combo_box.rs index b514db91c7..10c0f5278c 100644 --- a/crates/ui-widgets/src/pickers/combo_box.rs +++ b/crates/ui-widgets/src/pickers/combo_box.rs @@ -252,20 +252,20 @@ impl Component for ComboBox<'_> { } // A list closed by any path (a pick, Escape, a click outside, the draft ending) ends its preview. self.end_preview(cx); - let text = cx.value().cloned().unwrap_or_default(); while let Some((step, mods)) = cx.intents().take_move() { let forward = match step { NavMove::Down if !mods.fine => true, NavMove::Up if !mods.fine => false, _ => continue, }; - if let Some(value) = self.neighbour(&text, forward).and_then(|at| self.options[at].value()) { + let text = cx.value().map_or("", String::as_str); + if let Some(value) = self.neighbour(text, forward).and_then(|at| self.options[at].value()) { cx.set(value.clone()); } } if let Some(wheel) = cx.take_wheel() && wheel.scroll.y != 0.0 - && let Some(value) = self.neighbour(&text, wheel.scroll.y < 0.0).and_then(|at| self.options[at].value()) + && let Some(value) = self.neighbour(cx.value().map_or("", String::as_str), wheel.scroll.y < 0.0).and_then(|at| self.options[at].value()) { cx.set(value.clone()); } diff --git a/crates/ui-widgets/tests/it/pickers/combo_list.rs b/crates/ui-widgets/tests/it/pickers/combo_list.rs index a2eedcaf9b..e7c5c17268 100644 --- a/crates/ui-widgets/tests/it/pickers/combo_list.rs +++ b/crates/ui-widgets/tests/it/pickers/combo_list.rs @@ -38,6 +38,18 @@ fn reports(fixture: &mut Fixture) -> u32 { *fixture.data().value("reports", 0_u32) } +#[trial] +fn closed_combo_steps_for_each_arrow_in_one_frame() { + use craft_ui::testing::{focus, input}; + + let mut fixture = Fixture::story(&Story::new("combo_moves", combo)); + fixture.settle().key(Key::Tab, Modifiers::NONE).settle(); + assert!(!list_open(&mut fixture), "the combo's list stays closed"); + let step = || [input::key_press(Key::ArrowUp, Modifiers::NONE), focus::key_release(Key::ArrowUp, Modifiers::NONE)]; + fixture.frame([step(), step()].into_iter().flatten().collect()).settle(); + assert_eq!(font(&mut fixture), "Garamond", "the two ArrowUp presses should advance through Georgia"); +} + #[trial] fn the_hovered_option_is_previewed_until_the_pointer_leaves_the_list() { let mut fixture = Fixture::story(&Story::new("combo_preview", previewing));