From cf54d5e8a329d086f331a535769f74fb1a796796 Mon Sep 17 00:00:00 2001 From: Fabio Lussi Date: Sat, 10 Oct 2026 22:33:04 +0200 Subject: [PATCH] Keep the blend-mode preview between list rows (#2553) (#2612) The Layers panel blend-mode list previews the hovered mode, but egui's item spacing leaves a gap between rows that hovers no row, so moving the pointer down the list flashed the layer's current mode back at every gap. While the pointer is over the open list and between rows, report the nearest row as hovered, so the preview moves straight from one mode to the next. Co-authored-by: Fabio Lussi <198260595+itrycodinganditsbad@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/blend_preview/tests.rs | 20 ++++++++++++++++++++ crates/ui-egui/src/widgets.rs | 14 ++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/crates/ui-egui/src/blend_preview/tests.rs b/crates/ui-egui/src/blend_preview/tests.rs index 0ea840d723..4eb407aad0 100644 --- a/crates/ui-egui/src/blend_preview/tests.rs +++ b/crates/ui-egui/src/blend_preview/tests.rs @@ -104,3 +104,23 @@ fn hovering_the_layers_panel_blend_list_previews_and_a_click_commits() { assert_eq!(steps(h.state()), undo + 1, "choosing records one step"); assert_eq!(previewed(&mut h), None); } + +#[test] +fn moving_between_modes_keeps_a_preview_across_the_gaps_between_them() { + // #2553: the pointer between two rows used to hover neither, flashing the document back. + let (s, _) = session(); + let mut h = harness(s); + let dropdown = h.query_all_by_role(Role::ComboBox).map(|n| n.rect()).max_by(|a, b| a.top().total_cmp(&b.top())).unwrap(); + click(&mut h, dropdown.center()); + let (dissolve, darken) = (h.get_by_label("Dissolve").rect(), h.get_by_label("Darken").rect()); + assert!(darken.top() > dissolve.bottom(), "the rows have a gap between them"); + let multiply = h.get_by_label("Multiply").rect().center(); + let mut y = dissolve.center().y; + while y <= multiply.y { + h.hover_at(Pos2::new(multiply.x, y)); + h.run_steps(1); + assert!(previewed(&mut h).is_some(), "a mode previews at y = {y}"); + y += 0.5; + } + assert_eq!(previewed(&mut h), Some(BlendMode::Multiply)); +} diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 177f7f2c33..65dbbfa280 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -939,6 +939,9 @@ fn dropdown_with(ui: &mut Ui, id: &str, current: &mut T, o reveal |= wheeled; chosen.extend(stepped); } + // The row nearest the pointer, by its distance to each row. + let pointer = ui.ctx().pointer_hover_pos().filter(|_| ui.rect_contains_pointer(ui.clip_rect())); + let mut nearest: Option<(f32, &T)> = None; for (v, l) in options { let item = ui.selectable_label(v == current, tl!(l)); if reveal && v == current { @@ -947,11 +950,22 @@ fn dropdown_with(ui: &mut Ui, id: &str, current: &mut T, o if item.hovered() { hovered = Some(v.clone()); } + if let Some(p) = pointer { + let d = (item.rect.top() - p.y).max(p.y - item.rect.bottom()).max(0.0); + if nearest.is_none_or(|(n, _)| d < n) { + nearest = Some((d, v)); + } + } if item.clicked() { *current = v.clone(); chosen.push(v.clone()); } } + // Between two rows (item spacing) the pointer hovers neither; it is still over the list, + // so keep previewing the nearest row instead of flashing the current value back (#2553). + if hovered.is_none() { + hovered = nearest.map(|(_, v)| v.clone()); + } }); if combo_box_arrow_keys(ui, &response.response, current, options) { chosen.push(current.clone());