Merge pull request #3866 from dotCooCoo/fix/combo-box-queued-arrow-steps

Keep each queued arrow step in a closed ComboBox
This commit is contained in:
BFlat authored and GitHub committed 2026-11-27 14:24:05 +07:00
commit c0977ad612
2 files changed
+15 -3

No files matched your search

+3 -3
View File
@@ -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());
}
@@ -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));