From ec5bcc602de459b5e1846db0cacd0716a0f73669 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 12:28:28 +0100 Subject: [PATCH] Layers and Channels panels read the modifiers, not the pointer frame (#2812) Both panels read pointer::frame(..).mods on every pass: the Layers panel for its rows' held modifiers and its drop test, the Channels panel before it takes its commands. pointer::frame notes the pointer as a tracked input, so a memoized view holding either panel ran on every pointer move in the window. pointer::mods reads the same modifiers and notes only the modifiers. Trials: a pointer move beside each panel replays its host view and Alt held runs it; both fail without the change. Co-Authored-By: Claude Opus 5.5 --- crates/imaging/src/ui/channels/panel.rs | 2 +- crates/imaging/tests/it/channels_memo.rs | 52 ++++++++++++++++++++++++ crates/imaging/tests/it/main.rs | 1 + crates/layers/src/ui/panel/body.rs | 4 +- crates/layers/src/ui/panel/mod.rs | 2 +- crates/layers/tests/it/panel_memo.rs | 32 +++++++++++++++ 6 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 crates/imaging/tests/it/channels_memo.rs diff --git a/crates/imaging/src/ui/channels/panel.rs b/crates/imaging/src/ui/channels/panel.rs index fe9539467..f81be39e7 100644 --- a/crates/imaging/src/ui/channels/panel.rs +++ b/crates/imaging/src/ui/channels/panel.rs @@ -154,7 +154,7 @@ impl<'a, K: Clone + Eq + Hash + Debug + Send + Sync + 'static> ChannelsPanel<'a, events.borrow_mut().extend(out); }) .show(ui, |ui, stack| { - let mods = craft_ui::runtime::pointer::frame(&ctx).mods; + let mods = craft_ui::runtime::pointer::mods(&ctx); while let Some((command, _)) = stack.take_command::() { match (command, targeted_row(rows)) { (ChannelsCommands::RenameChannel, Some(row)) if row.kind.renames() => request_rename(&ctx, list, &row.key), diff --git a/crates/imaging/tests/it/channels_memo.rs b/crates/imaging/tests/it/channels_memo.rs new file mode 100644 index 000000000..bc42aced8 --- /dev/null +++ b/crates/imaging/tests/it/channels_memo.rs @@ -0,0 +1,52 @@ +//! The Channels panel in a host's memoized view: a pointer move beside it replays it (#2812). + +use craft_ui::contract::{MemoProps, MemoView}; +use craft_ui::testing::{Fixture, MemoRun, last_frame_memo_runs, pointer, trial}; +use egui::{Modifiers, Pos2, Rect, UiBuilder, Vec2}; + +use crate::ui::channels::{ChannelKind, ChannelRow, ChannelsPanel}; + +const PANEL: Vec2 = Vec2::new(320.0, 400.0); + +/// What a host's view of the panel reads: its rows, which the host's revision stands for. +#[derive(MemoProps)] +struct Host<'a> { + revision: u64, + #[memo_props(covered_by = "revision", reason = "the rows are fixed in this trial")] + rows: &'a [ChannelRow], +} + +fn host(props: &mut Host<'_>, ui: &mut egui::Ui) { + let _ = ChannelsPanel::new(props.rows).show(ui); +} + +/// The panel reads the modifiers its commands take, not the pointer: a pointer move beside it replays its view, and a +/// modifier change runs it. Before, every pointer move in the window ran it. +#[trial] +fn a_pointer_move_beside_the_panel_replays_it_and_a_modifier_runs_it() { + let rows = + [(0, ChannelKind::Composite, "RGB"), (1, ChannelKind::Color, "Red"), (2, ChannelKind::Color, "Green"), (3, ChannelKind::Color, "Blue")] + .map(|(key, kind, name)| ChannelRow::new(key, kind, name)); + let mut fixture = Fixture::new(move |ui| { + let at = Rect::from_min_size(ui.max_rect().min, PANEL); + ui.scope_builder(UiBuilder::new().max_rect(at), |ui| { + MemoView::new("channels", Host { revision: 0, rows: &rows }, host).show(ui); + }); + }); + fixture.room(Vec2::new(PANEL.x + 400.0, PANEL.y)).settle().idle(2); + let runs = |fixture: &Fixture| { + let runs = last_frame_memo_runs(fixture.ctx()); + let count = |wanted: MemoRun| runs.iter().filter(|(name, _, run)| name.contains("Host") && *run == wanted).count(); + (count(MemoRun::Ran), count(MemoRun::Replayed)) + }; + // The pointer enters the window beside the panel; in an app it is already there. + fixture.frame(vec![pointer::moved(Pos2::new(PANEL.x + 200.0, 90.0))]); + for step in 0..3 { + fixture.frame(vec![pointer::moved(Pos2::new(PANEL.x + 200.0, 100.0 + step as f32 * 10.0))]); + assert_eq!(runs(&fixture), (0, 1), "pointer move {step} beside the panel replays its view"); + } + fixture.hold(Modifiers::ALT).frame(Vec::new()); + assert_eq!(runs(&fixture).0, 1, "Alt held runs the view"); + fixture.frame(Vec::new()); + assert_eq!(runs(&fixture), (0, 1), "and it replays while Alt stays held"); +} diff --git a/crates/imaging/tests/it/main.rs b/crates/imaging/tests/it/main.rs index 2a7b0442b..250998236 100644 --- a/crates/imaging/tests/it/main.rs +++ b/crates/imaging/tests/it/main.rs @@ -4,6 +4,7 @@ pub(crate) mod adjust_editors; pub(crate) mod adjust_tone; pub(crate) mod blur_pins; pub(crate) mod channels_delete; +pub(crate) mod channels_memo; pub(crate) mod color_range; pub(crate) mod contour_field; pub(crate) mod curve; diff --git a/crates/layers/src/ui/panel/body.rs b/crates/layers/src/ui/panel/body.rs index 155359e35..94c6371a4 100644 --- a/crates/layers/src/ui/panel/body.rs +++ b/crates/layers/src/ui/panel/body.rs @@ -76,9 +76,7 @@ pub(super) fn show_body( .columns(columns) .selection(Bind::bound(&mut selection)) .can_rename(|key| matches!(key, LayerRowKey::Layer(id) if tree.info(id).renamable)) - .accepts(|drag: &ListDrag>, _over, insert| { - accepts_drop(tree, drag, order, insert, craft_ui::runtime::pointer::frame(&ctx).mods) - }) + .accepts(|drag: &ListDrag>, _over, insert| accepts_drop(tree, drag, order, insert, craft_ui::runtime::pointer::mods(&ctx))) .drag_payload({ let document = cx.document; move |drag: &ListDrag>| Some(LayersDrag::of_rows(drag, document)) diff --git a/crates/layers/src/ui/panel/mod.rs b/crates/layers/src/ui/panel/mod.rs index 65073fec8..21f08aff0 100644 --- a/crates/layers/src/ui/panel/mod.rs +++ b/crates/layers/src/ui/panel/mod.rs @@ -378,7 +378,7 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> { lock_column, visibility_key, trailing: trailing.as_deref(), - held: craft_ui::runtime::pointer::frame(ui.ctx()).mods, + held: craft_ui::runtime::pointer::mods(ui.ctx()), }; let events = RefCell::new(Vec::new()); let current = RefCell::new(LayerFilter::default()); diff --git a/crates/layers/tests/it/panel_memo.rs b/crates/layers/tests/it/panel_memo.rs index 5f72626bf..753c3f8e4 100644 --- a/crates/layers/tests/it/panel_memo.rs +++ b/crates/layers/tests/it/panel_memo.rs @@ -132,3 +132,35 @@ fn a_clicks_event_is_delivered_once_across_the_run_and_the_replays() { let selects = rig.seen.borrow().iter().filter(|event| matches!(event, LayersEvent::Select(_))).count(); assert_eq!(selects, 1, "{:?}", rig.seen.borrow()); } + +/// A pointer move beside the panel replays its view: the panel reads the modifiers it shows its rows with, not the +/// pointer, so only a modifier change runs it (#2812). Before, every pointer move in the window ran it. +#[trial] +fn a_pointer_move_beside_the_panel_replays_it_and_a_modifier_runs_it() { + let tree = Tracked::new(FakeLayers::fifty()); + let mut fixture = Fixture::new(move |ui| { + let mut filter = LayerFilter::default(); + let mut events = Vec::new(); + let at = egui::Rect::from_min_size(ui.max_rect().min, PANEL); + ui.scope_builder(egui::UiBuilder::new().max_rect(at), |ui| { + MemoView::new("layers", Host { tree: &tree, filter: Bind::bound(&mut filter), events: Outbox::new(&mut events) }, host).show(ui); + }); + }); + fixture.room(Vec2::new(PANEL.x + 400.0, PANEL.y)); + fixture.settle().idle(2); + let runs = |fixture: &Fixture| { + let runs = last_frame_memo_runs(fixture.ctx()); + let count = |wanted: MemoRun| runs.iter().filter(|(name, _, run)| name.contains("Host") && *run == wanted).count(); + (count(MemoRun::Ran), count(MemoRun::Replayed)) + }; + // The pointer enters the window beside the panel; in an app it is already there. + fixture.frame(vec![pointer::moved(egui::Pos2::new(PANEL.x + 200.0, 90.0))]); + for step in 0..3 { + fixture.frame(vec![pointer::moved(egui::Pos2::new(PANEL.x + 200.0, 100.0 + step as f32 * 10.0))]); + assert_eq!(runs(&fixture), (0, 1), "pointer move {step} beside the panel replays its view"); + } + fixture.hold(egui::Modifiers::ALT).frame(Vec::new()); + assert_eq!(runs(&fixture).0, 1, "Alt held runs the view"); + fixture.frame(Vec::new()); + assert_eq!(runs(&fixture), (0, 1), "and it replays while Alt stays held"); +}