From 20583b38efef27da5f9afaffa170c01b13949e0a Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Tue, 27 Oct 2026 19:56:01 +0800 Subject: [PATCH 01/11] fix: dismiss context menu without triggering tool action on outside click When a canvas tool menu (Zoom/Hand view menu, selection menu, etc.) is open and the user clicks outside it to dismiss it, that click should not also trigger the underlying tool action (e.g., zoom step). This matches Photoshop behavior where the dismissal click is consumed. Fixes #9832 --- crates/ui-egui/src/canvas.rs | 135 +++++++++++++++++++++++++---------- 1 file changed, 96 insertions(+), 39 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 75ecf186f2..677193fa3d 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1157,48 +1157,105 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: && let Some(p) = response.interact_pointer_pos() { let click_button = if app.secondary_erase { PointerButton::Secondary } else { PointerButton::Primary }; - let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods); - let click_mods = if tool == Tool::ObjectSelection && click_button == PointerButton::Primary { - ctx.data(|d| d.get_temp(tool_press)).unwrap_or(click_mods) + if let Some(menu) = &app.ui.canvas_tool_menu { + // If a canvas tool menu is open and this click is outside it, the click will + // dismiss the menu and should not also trigger a tool action (Photoshop behavior). + let menu_rect = egui::Rect::from_min_size( + egui::pos2(menu.pos[0], menu.pos[1]), + egui::vec2(200.0, 200.0), // conservative height estimate + ); + if !menu_rect.contains(p) { + // Click is outside the open menu - it will dismiss the menu, don't trigger tool action. + } else { + let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods); + let click_mods = if tool == Tool::ObjectSelection && click_button == PointerButton::Primary { + ctx.data(|d| d.get_temp(tool_press)).unwrap_or(click_mods) + } else { + click_mods + }; + let d = xf.to_doc(p); + match tool { + Tool::Zoom if !transform_owns_pointer => { + let nz = crate::zoom_levels::step(view.zoom, if zoom_out(click_mods.alt) { -1 } else { 1 }, view.doc_size); + let center = app.session.prefs().tools.zoom_clicked_point_to_center; + let doc_anchor = xf.to_doc(p); + let screen_anchor = p; + zoom_about(&mut view, &xf, p, nz, center, ppp); + view.request_zoom_animation(app.session.prefs().general.animated_zoom && nz != display_view.zoom); + view.zoom_anchor = (view.zoom_animating && !center).then_some((doc_anchor, [screen_anchor.x, screen_anchor.y])); + } + // A click with the (temporary) Hand does nothing, never the tool underneath. + Tool::Hand | Tool::RotateView => {} + // Double-clicking closes the polygonal lasso: the first click placed the last + // vertex (or already closed it), so the second never starts a new polygon. egui + // reports it as a triple click when a vertex went down shortly before. + Tool::PolygonLasso if response.double_clicked() || response.triple_clicked() => commit_polygon(app), + // The same for the Magnetic Lasso: along the edges, or straight with ⌥. + Tool::MagneticLasso if response.double_clicked() || response.triple_clicked() => crate::magnetic_lasso_ui::close(app, mods.alt), + // The first click placed (or grabbed) the point; the second toggles it. + Tool::CurvaturePen if response.double_clicked() => crate::vector_ui::curvature_toggle(app, d[0], d[1]), + // Double-clicking a guide opens Preferences › Guides, Grid & Slices, as in Photoshop. + Tool::Move if response.double_clicked() && crate::rulers::guide_at(app, d[0], d[1]).is_some() => { + if let Err(e) = crate::menus::invoke(app, &ctx, "edit.preferences.guidesGridAndSlices", json!({})) { + app.ui.status = e; + } + } + _ => { + if tool == Tool::Move && app.ui.transform.is_none() { + begin_transform_controls_at(app, &ctx, &xf, p); + } + // If this tool was not handled on pointer-down, fall back to a + // click-sized gesture while preserving pen pressure (mouse stays at 1). + tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: app.stylus.pressure() }, click_mods); + tap_at_peak_pressure(app); + tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, click_mods); + } + } + } } else { - click_mods - }; - let d = xf.to_doc(p); - match tool { - Tool::Zoom if !transform_owns_pointer => { - let nz = crate::zoom_levels::step(view.zoom, if zoom_out(click_mods.alt) { -1 } else { 1 }, view.doc_size); - let center = app.session.prefs().tools.zoom_clicked_point_to_center; - let doc_anchor = xf.to_doc(p); - let screen_anchor = p; - zoom_about(&mut view, &xf, p, nz, center, ppp); - view.request_zoom_animation(app.session.prefs().general.animated_zoom && nz != display_view.zoom); - view.zoom_anchor = (view.zoom_animating && !center).then_some((doc_anchor, [screen_anchor.x, screen_anchor.y])); - } - // A click with the (temporary) Hand does nothing, never the tool underneath. - Tool::Hand | Tool::RotateView => {} - // Double-clicking closes the polygonal lasso: the first click placed the last - // vertex (or already closed it), so the second never starts a new polygon. egui - // reports it as a triple click when a vertex went down shortly before. - Tool::PolygonLasso if response.double_clicked() || response.triple_clicked() => commit_polygon(app), - // The same for the Magnetic Lasso: along the edges, or straight with ⌥. - Tool::MagneticLasso if response.double_clicked() || response.triple_clicked() => crate::magnetic_lasso_ui::close(app, mods.alt), - // The first click placed (or grabbed) the point; the second toggles it. - Tool::CurvaturePen if response.double_clicked() => crate::vector_ui::curvature_toggle(app, d[0], d[1]), - // Double-clicking a guide opens Preferences › Guides, Grid & Slices, as in Photoshop. - Tool::Move if response.double_clicked() && crate::rulers::guide_at(app, d[0], d[1]).is_some() => { - if let Err(e) = crate::menus::invoke(app, &ctx, "edit.preferences.guidesGridAndSlices", json!({})) { - app.ui.status = e; + let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods); + let click_mods = if tool == Tool::ObjectSelection && click_button == PointerButton::Primary { + ctx.data(|d| d.get_temp(tool_press)).unwrap_or(click_mods) + } else { + click_mods + }; + let d = xf.to_doc(p); + match tool { + Tool::Zoom if !transform_owns_pointer => { + let nz = crate::zoom_levels::step(view.zoom, if zoom_out(click_mods.alt) { -1 } else { 1 }, view.doc_size); + let center = app.session.prefs().tools.zoom_clicked_point_to_center; + let doc_anchor = xf.to_doc(p); + let screen_anchor = p; + zoom_about(&mut view, &xf, p, nz, center, ppp); + view.request_zoom_animation(app.session.prefs().general.animated_zoom && nz != display_view.zoom); + view.zoom_anchor = (view.zoom_animating && !center).then_some((doc_anchor, [screen_anchor.x, screen_anchor.y])); } - } - _ => { - if tool == Tool::Move && app.ui.transform.is_none() { - begin_transform_controls_at(app, &ctx, &xf, p); + // A click with the (temporary) Hand does nothing, never the tool underneath. + Tool::Hand | Tool::RotateView => {} + // Double-clicking closes the polygonal lasso: the first click placed the last + // vertex (or already closed it), so the second never starts a new polygon. egui + // reports it as a triple click when a vertex went down shortly before. + Tool::PolygonLasso if response.double_clicked() || response.triple_clicked() => commit_polygon(app), + // The same for the Magnetic Lasso: along the edges, or straight with ⌥. + Tool::MagneticLasso if response.double_clicked() || response.triple_clicked() => crate::magnetic_lasso_ui::close(app, mods.alt), + // The first click placed (or grabbed) the point; the second toggles it. + Tool::CurvaturePen if response.double_clicked() => crate::vector_ui::curvature_toggle(app, d[0], d[1]), + // Double-clicking a guide opens Preferences › Guides, Grid & Slices, as in Photoshop. + Tool::Move if response.double_clicked() && crate::rulers::guide_at(app, d[0], d[1]).is_some() => { + if let Err(e) = crate::menus::invoke(app, &ctx, "edit.preferences.guidesGridAndSlices", json!({})) { + app.ui.status = e; + } + } + _ => { + if tool == Tool::Move && app.ui.transform.is_none() { + begin_transform_controls_at(app, &ctx, &xf, p); + } + // If this tool was not handled on pointer-down, fall back to a + // click-sized gesture while preserving pen pressure (mouse stays at 1). + tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: app.stylus.pressure() }, click_mods); + tap_at_peak_pressure(app); + tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, click_mods); } - // If this tool was not handled on pointer-down, fall back to a - // click-sized gesture while preserving pen pressure (mouse stays at 1). - tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: app.stylus.pressure() }, click_mods); - tap_at_peak_pressure(app); - tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, click_mods); } } } From 712b0fb892550fad8fde5d796d32158ae506dcc9 Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Tue, 27 Oct 2026 20:16:01 +0800 Subject: [PATCH 02/11] fix: dismiss context menu without triggering tool action on outside click When a canvas tool menu (Zoom/Hand view menu, selection menu, etc.) is open and the user clicks outside it to dismiss it, that click should not also trigger the underlying tool action (e.g., zoom step). This matches Photoshop behavior where the dismissal click is consumed. Fixes #9832 **Changes:** - Added flag to to track when an outside press dismisses the menu - Set flag in when returns true - Added function using actual rendered menu rect from egui's area memory - In click handler: check dismissed flag first (consume release click), then use accurate menu rect for hit-test **Testing:** - All existing tests pass (canvas_tool_menu, zoom_tool, etc.): 60 passed - clippy passes - cargo xtask layers passes - cargo xtask wasm passes - panic_hunt test passes --- crates/ui-egui/src/canvas.rs | 13 +++++++------ crates/ui-egui/src/canvas/canvas_tool_menu.rs | 12 ++++++++++++ crates/ui-egui/src/state.rs | 5 +++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 677193fa3d..63d7b434f1 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1156,17 +1156,17 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: if buttons.clicked && let Some(p) = response.interact_pointer_pos() { - let click_button = if app.secondary_erase { PointerButton::Secondary } else { PointerButton::Primary }; - if let Some(menu) = &app.ui.canvas_tool_menu { + // If an outside press dismissed the canvas tool menu, consume this release click + // so it doesn't also trigger a tool action (Photoshop behavior). + if app.ui.canvas_tool_menu_dismissed { + app.ui.canvas_tool_menu_dismissed = false; + } else if let Some(menu_rect) = crate::canvas_tool_menu::menu_rect_if_open(app, &ctx) { // If a canvas tool menu is open and this click is outside it, the click will // dismiss the menu and should not also trigger a tool action (Photoshop behavior). - let menu_rect = egui::Rect::from_min_size( - egui::pos2(menu.pos[0], menu.pos[1]), - egui::vec2(200.0, 200.0), // conservative height estimate - ); if !menu_rect.contains(p) { // Click is outside the open menu - it will dismiss the menu, don't trigger tool action. } else { + let click_button = if app.secondary_erase { PointerButton::Secondary } else { PointerButton::Primary }; let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods); let click_mods = if tool == Tool::ObjectSelection && click_button == PointerButton::Primary { ctx.data(|d| d.get_temp(tool_press)).unwrap_or(click_mods) @@ -1213,6 +1213,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: } } } else { + let click_button = if app.secondary_erase { PointerButton::Secondary } else { PointerButton::Primary }; let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods); let click_mods = if tool == Tool::ObjectSelection && click_button == PointerButton::Primary { ctx.data(|d| d.get_temp(tool_press)).unwrap_or(click_mods) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index dd9b635e64..2166202590 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -1173,8 +1173,20 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) { choose(app, ctx, &command); } else if crate::canvas_popup::outside_pressed(ctx, id, area.response.rect) { app.ui.canvas_tool_menu = None; + app.ui.canvas_tool_menu_dismissed = true; } } +/// Returns the menu rect if the canvas tool menu is currently open, for hit-testing +/// outside-click dismissal in the click handler. +pub fn menu_rect_if_open(app: &PhotocraftApp, ctx: &Context) -> Option { + let menu = app.ui.canvas_tool_menu.as_ref()?; + let id = menu_id(); + let screen = ctx.content_rect(); + let size = ctx.memory(|m| m.area_rect(id)).map_or(egui::vec2(210.0, 140.0), |r| r.size()); + let pos = egui::pos2(menu.pos[0].min(screen.right() - size.x).max(screen.left()), menu.pos[1].min(screen.bottom() - size.y).max(screen.top())); + Some(egui::Rect::from_min_size(pos, size)) +} + #[cfg(test)] mod tests; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index ef587063cb..1a6452cbb0 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -287,6 +287,10 @@ pub struct UiState { /// Selection-tool context menu opened by a plain canvas right-click. #[serde(default)] pub canvas_tool_menu: Option, + /// An outside press dismissed the canvas tool menu; suppress the corresponding + /// release click from triggering a tool action. + #[serde(default)] + pub canvas_tool_menu_dismissed: bool, /// The guide a Move-tool click selected (`guide_select`): drawn blue, Delete removes it. #[serde(default)] pub selected_guide: Option, @@ -507,6 +511,7 @@ impl Default for UiState { brush_picker_size: None, layer_menu: None, canvas_tool_menu: None, + canvas_tool_menu_dismissed: false, selected_guide: None, brush_tool: Tool::Brush, tool_brushes: Vec::new(), From 6cb37eea57241ce7fbfb6042b84f84b907e9fa81 Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Tue, 27 Oct 2026 22:34:21 +0800 Subject: [PATCH 03/11] fix: block tool input on outside press and clear dismissal flag on release Addresses CodeRabbit review comments on PR #9841: 1. Clear flag on pointer release (primary or secondary), even when release occurs outside canvas and produces no event. This prevents the next ordinary canvas click from being incorrectly suppressed. 2. Block tool input (Down, Move, Up events) on outside press before tool handlers run, not just on click. The press that dismisses the menu is now detected early via and its gesture is fully consumed (no stroke starts, no drag moves, no click action). Files changed: - crates/ui-egui/src/canvas.rs: Added pointer release flag clearing, added detection, and gated all tool_event calls with this flag. --- crates/ui-egui/src/canvas.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 63d7b434f1..dd2ddffbf4 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -888,6 +888,25 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: // (Preferences › Tools, `paint_mouse`). crate::paint_mouse::sync_tool_brush(app); let mut buttons = crate::paint_mouse::canvas_buttons(app, &response, tool); + + // Clear the menu dismissal flag on the corresponding pointer release, even when the + // release occurs outside the canvas and produces no `buttons.clicked` event. + // This prevents the next ordinary canvas click from being incorrectly suppressed. + if app.ui.canvas_tool_menu_dismissed + && (ui.input(|i| i.pointer.primary_released()) || ui.input(|i| i.pointer.secondary_released())) + { + app.ui.canvas_tool_menu_dismissed = false; + } + + // Determine if the current press (if any) is outside an open canvas tool menu. + // If so, we should suppress tool input for this gesture (press, drag, click). + // This prevents the press from starting a stroke or other tool action that the + // click handler cannot undo. + let menu_dismiss_press = crate::canvas_tool_menu::menu_rect_if_open(app, &ctx).is_some_and(|r| { + response.interact_pointer_pos().is_some_and(|p| !r.contains(p)) + || ui.input(|i| i.pointer.press_origin()).is_some_and(|p| rect.contains(p) && !r.contains(p)) + }); + // The Crop tool's frame is edited from the press (before egui's drag threshold), so the // pixels past the canvas show at once, as in Photoshop. if tool == Tool::Crop && response.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down()) && crate::crop_ui::press(app) { @@ -899,6 +918,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: || matches!(tool, Tool::RectMarquee | Tool::EllipseMarquee | Tool::SingleRowMarquee | Tool::SingleColumnMarquee | Tool::ObjectSelection); let tool_press = egui::Id::unique(("tool-pointer-press-modifiers", idx)); if capture_press + && !menu_dismiss_press && let Some((p, press_mods)) = ui.input(|i| { i.events.iter().find_map(|e| match e { egui::Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers } if rect.contains(*pos) => { @@ -1026,6 +1046,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: let right_down = ui.input(|i| i.pointer.secondary_down()) || physical_right; if strokes_live(tool) && !right_down + && !menu_dismiss_press && app.drag.is_none() && response.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_pressed()) @@ -1044,6 +1065,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: buttons.started = false; } if buttons.started + && !menu_dismiss_press && let Some(p) = ui.input(|i| i.pointer.press_origin()).filter(|p| rect.contains(*p)).or(response.interact_pointer_pos()) { if tool == Tool::Move && app.ui.transform.is_none() { @@ -1057,7 +1079,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: // recognises a drag (past its click distance): otherwise the first few points are lost // and the stroke starts with a straight segment and no pressure ramp. let press_stroke_moving = press_stroke && app.drag.is_some(); - if buttons.dragged || buttons.stopped || press_stroke_moving { + if !menu_dismiss_press && (buttons.dragged || buttons.stopped || press_stroke_moving) { // Feed every pointer move the OS delivered this frame, not just the latest position, so // a fast stroke is sampled densely and renders as a smooth curve instead of a coarse // polyline. egui-winit pushes one `PointerMoved` per `CursorMoved`, and they accumulate @@ -1115,7 +1137,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: feed_live_stroke(app); crate::magnetic_lasso_ui::flush(app); } - if buttons.stopped { + if buttons.stopped && !menu_dismiss_press { // The live painting press already created the stroke and this release commits it. // egui may also report clicked on the same release; replaying that click paints a // second full-pressure dab over the real (possibly light-pressure) pen dab. @@ -1140,7 +1162,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: } // A stroke started on the press ends with the release, whether egui saw a drag, a click, // or neither (a long press that never moved). - if press_stroke && !buttons.stopped && ui.input(|i| i.pointer.primary_released()) { + if press_stroke && !buttons.stopped && !menu_dismiss_press && ui.input(|i| i.pointer.primary_released()) { buttons.clicked = false; let p = response.interact_pointer_pos().map(|p| xf.to_doc(p)).or_else(|| app.drag.as_ref().and_then(|d| d.points.last().map(|q| [q[0], q[1]]))); if let Some(d) = p @@ -1261,7 +1283,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: } } // Magnetic Lasso: between clicks the border follows the pointer with the button up. - if tool == Tool::MagneticLasso && app.ui.magnetic.active() && !(buttons.started || buttons.dragged || buttons.stopped) && response.hovered() { + if tool == Tool::MagneticLasso && app.ui.magnetic.active() && !(buttons.started || buttons.dragged || buttons.stopped) && !menu_dismiss_press && response.hovered() { let moves: Vec = ui.input(|i| i.events.iter().filter_map(|e| if let egui::Event::PointerMoved(p) = e { Some(*p) } else { None }).collect()); app.defer_live_stroke = true; for p in moves.into_iter().filter(|p| rect.contains(*p)) { From 78b1dfe448a820cc8770252051e3c6c868ccc8d9 Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Wed, 28 Oct 2026 12:02:46 +0800 Subject: [PATCH 04/11] fix: consume the dismissal gesture through its release and block the zoom hold Addresses the two remaining CodeRabbit findings on PR #9841: - The dismissal flag is cleared below the click handling, so a later-frame release over the canvas is consumed by the flag check first (clearing it before let that release zoom). canvas_tool_menu::show does not arm the flag when the frame already contains the release, so a fast same-frame click cannot eat the next ordinary click. - The blocked gesture now persists in canvas_tool_menu_dismissed until its release instead of being re-derived from the open menu each frame, so a held dismissal press stays blocked after the menu closes. Navigation is blocked too: the animated zoom hold cannot arm on it, and zoom drags, Rotate View and other button-driven gestures are starved. Regression tests (fail on the previous commit, pass now): - dismissing_the_view_menu_consumes_the_whole_gesture - a_held_menu_dismissal_press_never_arms_the_zoom_hold --- crates/ui-egui/src/canvas.rs | 57 ++++++++---- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 6 +- .../src/canvas/canvas_tool_menu/tests.rs | 93 +++++++++++++++++++ 3 files changed, 136 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index dd2ddffbf4..7a5d16dbe7 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -889,27 +889,32 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: crate::paint_mouse::sync_tool_brush(app); let mut buttons = crate::paint_mouse::canvas_buttons(app, &response, tool); - // Clear the menu dismissal flag on the corresponding pointer release, even when the - // release occurs outside the canvas and produces no `buttons.clicked` event. - // This prevents the next ordinary canvas click from being incorrectly suppressed. - if app.ui.canvas_tool_menu_dismissed - && (ui.input(|i| i.pointer.primary_released()) || ui.input(|i| i.pointer.secondary_released())) - { - app.ui.canvas_tool_menu_dismissed = false; + // A press outside an open canvas tool menu dismisses it (`canvas_tool_menu::show`, after + // this input pass) and the whole gesture is consumed until its release, as in Photoshop: + // no tool press, stroke, drag or zoom step. The menu closes mid-frame (after this input + // pass), so the open-menu hit test covers the dismissal frame and the flag persists the + // block for the frames after it, until the release clear below the click handling. + let menu_dismiss_press = app.ui.canvas_tool_menu_dismissed + || crate::canvas_tool_menu::menu_rect_if_open(app, &ctx).is_some_and(|r| { + ui.input(|i| i.pointer.press_origin()).is_some_and(|p| !r.contains(p)) + }); + if menu_dismiss_press { + // Navigation and drags read `buttons` directly (zoom holds and drags, Rotate View): + // starve them. The release click stays armed, so the click handling below consumes + // it through the flag. + buttons.started = false; + buttons.dragged = false; + buttons.stopped = false; } - // Determine if the current press (if any) is outside an open canvas tool menu. - // If so, we should suppress tool input for this gesture (press, drag, click). - // This prevents the press from starting a stroke or other tool action that the - // click handler cannot undo. - let menu_dismiss_press = crate::canvas_tool_menu::menu_rect_if_open(app, &ctx).is_some_and(|r| { - response.interact_pointer_pos().is_some_and(|p| !r.contains(p)) - || ui.input(|i| i.pointer.press_origin()).is_some_and(|p| rect.contains(p) && !r.contains(p)) - }); - // The Crop tool's frame is edited from the press (before egui's drag threshold), so the // pixels past the canvas show at once, as in Photoshop. - if tool == Tool::Crop && response.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down()) && crate::crop_ui::press(app) { + if tool == Tool::Crop + && !menu_dismiss_press + && response.is_pointer_button_down_on() + && ui.input(|i| i.pointer.primary_down()) + && crate::crop_ui::press(app) + { ctx.request_repaint(); } // Capture intent at the press, before egui's drag threshold or click replay on release: @@ -1018,10 +1023,11 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: (buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false); } // Animated Zoom: a Zoom press held still zooms continuously (zoom_hold.rs); while it does, - // it owns the press: no scrub, and its release is no click step. + // it owns the press: no scrub, and its release is no click step. A menu-dismissal press + // must not arm it: holding the dismissal click would zoom (CodeRabbit, #9841). if tool == Tool::Zoom && !transform_owns_pointer { let out = zoom_out(ui.input(|i| i.modifiers.alt)); - let on_canvas = !under_dialog && !over_compass && response.is_pointer_button_down_on(); + let on_canvas = !menu_dismiss_press && !under_dialog && !over_compass && response.is_pointer_button_down_on(); let hold = crate::zoom_hold::hold_id(idx, primary, ctx.viewport_id()); if crate::zoom_hold::update(&ctx, &mut view, &xf, app.session.prefs().general.animated_zoom, out, ppp, on_canvas, hold) { (buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false); @@ -1282,6 +1288,19 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: } } } + // Clear the menu-dismissal flag on the gesture's pointer release, even when the release + // occurs outside the canvas and produces no `buttons.clicked` event. It sits below (not + // above) the click handling, so a release over the canvas in a later frame is first + // consumed by the flag check there: clearing before it would let that release zoom + // (CodeRabbit, #9841). The all-buttons-up check also covers a release that landed in a + // frame this canvas didn't render. + if app.ui.canvas_tool_menu_dismissed + && (ui.input(|i| i.pointer.primary_released()) + || ui.input(|i| i.pointer.secondary_released()) + || !ui.input(|i| i.pointer.any_down())) + { + app.ui.canvas_tool_menu_dismissed = false; + } // Magnetic Lasso: between clicks the border follows the pointer with the button up. if tool == Tool::MagneticLasso && app.ui.magnetic.active() && !(buttons.started || buttons.dragged || buttons.stopped) && !menu_dismiss_press && response.hovered() { let moves: Vec = ui.input(|i| i.events.iter().filter_map(|e| if let egui::Event::PointerMoved(p) = e { Some(*p) } else { None }).collect()); diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 2166202590..292cfb3bb4 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -1173,7 +1173,11 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) { choose(app, ctx, &command); } else if crate::canvas_popup::outside_pressed(ctx, id, area.response.rect) { app.ui.canvas_tool_menu = None; - app.ui.canvas_tool_menu_dismissed = true; + // A fast click can press and release in one frame: the canvas input above already + // suppressed its action through the open-menu hit test, and the deferred release clear + // (in `canvas_view`, below the click handling) would never fire after this frame. Don't + // arm the flag then, or it would eat the next ordinary click (CodeRabbit, #9841). + app.ui.canvas_tool_menu_dismissed = !ctx.input(|i| i.pointer.any_released()); } } diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs index eb9147a7a5..1a1679e6c9 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs @@ -546,6 +546,99 @@ fn zoom_and_hand_right_click_opens_the_view_menu() { } } +/// A zoom harness with a fixed camera: zoom 1.0 centred on the 400×300 document. `animated` is +/// Preferences › General › Animated Zoom; each step is 0.1 s of egui time, so a hold can pass +/// `zoom_hold::DELAY` within a few steps. +fn zoom_harness(animated: bool) -> Harness<'static, PhotocraftApp> { + let mut app = zoom_app(400, 300); + app.ui.tool = Tool::Zoom; + app.run("prefs.set", json!({"values": {"general.animatedZoom": animated, "tools.zoomClickedPointToCenter": false, "tools.overscroll": true}})).unwrap(); + app.sync_views(); + app.ui.extras.rulers = false; + let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(0.1).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui)); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::default()); + h.run_steps(4); + let view = &mut h.state_mut().ui.views[0]; + view.zoom = 1.0; + view.center = [200.0, 150.0]; + view.fit_pending = false; + view.fill_pending = false; + h.run_steps(2); + h +} + +/// The menu opens at `[300, 100]` (doc points); this press lands 250 doc px to its left: outside +/// the 200 px-wide menu, on the canvas. +fn dismissal_point(h: &Harness<'static, PhotocraftApp>) -> Pos2 { + screen_of(h.state(), [50.0, 250.0]) +} + +/// #9832: a left press outside the open view menu dismisses it, and the whole gesture is +/// consumed — the press, the held press, and the release never zoom, and the next ordinary +/// click zooms again. +#[test] +fn dismissing_the_view_menu_consumes_the_whole_gesture() { + let mut h = zoom_harness(false); + let zoom = h.state().ui.views[0].zoom; + let open_at = screen_of(h.state(), [300.0, 100.0]); + right_click(&mut h, open_at, Modifiers::NONE); + assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the view menu"); + // The dismissal press: the menu goes, the zoom does not. + let far = dismissal_point(&h); + h.event(egui::Event::PointerMoved(far)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu"); + assert_eq!(h.state().ui.views[0].zoom, zoom, "the dismissal press does not zoom"); + // Holding it (a long press releases as a click) still does nothing… + h.run_steps(2); + assert_eq!(h.state().ui.views[0].zoom, zoom, "a held dismissal press does not zoom"); + // …and the release over the canvas is consumed: no zoom step. + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + assert_eq!(h.state().ui.views[0].zoom, zoom, "the dismissal release does not zoom"); + // The next ordinary click zooms again: the gesture flag did not stick. + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + assert_eq!(h.state().ui.views[0].zoom, crate::zoom_levels::step(zoom, 1, h.state().ui.views[0].doc_size), "the next ordinary click zooms"); +} + +/// #9832: a menu-dismissal press held past `zoom_hold::DELAY` must not arm the animated zoom +/// hold: holding the dismissal click would otherwise zoom continuously. +#[test] +fn a_held_menu_dismissal_press_never_arms_the_zoom_hold() { + let mut h = zoom_harness(true); + let zoom = h.state().ui.views[0].zoom; + let open_at = screen_of(h.state(), [300.0, 100.0]); + right_click(&mut h, open_at, Modifiers::NONE); + assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the view menu"); + let far = dismissal_point(&h); + h.event(egui::Event::PointerMoved(far)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu"); + // 0.8 s held still, well past the 0.3 s hold delay: every frame stays at the start zoom. + for i in 0..8 { + h.run_steps(1); + assert_eq!(h.state().ui.views[0].zoom, zoom, "held dismissal press frame {i} must not zoom"); + } + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + assert_eq!(h.state().ui.views[0].zoom, zoom, "the dismissal release does not zoom either"); +} + #[test] fn view_menu_zoom_in_keeps_the_clicked_point_under_the_pointer() { let mut app = zoom_app(400, 300); From 2aa62a81d28d30ded03e7b6af00a1a8c719c2e42 Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Wed, 28 Oct 2026 12:39:39 +0800 Subject: [PATCH 05/11] fix: gate the Hand and flick pans on the menu-dismissal press too The flick-pan frame and the Hand pan read response.dragged() directly, before menu_dismiss_press is computed, and live in the hand_pan branch where the zeroed buttons never arrive: with the menu dismissed and the dismissing button still down, holding Space (or the selected Hand tool) and dragging panned the view. The gate is now computed up front and guards both pan sites (CodeRabbit, #9841). Regression test a_held_menu_dismissal_press_cannot_pan_the_view fails on the previous commit and passes now. --- crates/ui-egui/src/canvas.rs | 24 +++++----- .../src/canvas/canvas_tool_menu/tests.rs | 44 +++++++++++++++++++ 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 7a5d16dbe7..1c6ae43be8 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -839,10 +839,21 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: // box is only drawn and driven on the primary canvas. let transform_owns_pointer = primary && app.ui.transform.is_some() && temporary.is_none() && !middle; let hand_pan = tool == Tool::Hand && !transform_owns_pointer; + // A press outside an open canvas tool menu dismisses it (`canvas_tool_menu::show`, after this + // input pass) and the whole gesture is consumed until its release, as in Photoshop: no tool + // press, stroke, drag, pan or zoom step. The menu closes mid-frame (after this input pass), so + // the open-menu hit test covers the dismissal frame, and the flag persists the block for the + // frames after it, until the release clear below the click handling. It gates the Hand and + // flick pans below too: they read `response.dragged()` directly and never see `buttons` + // (CodeRabbit, #9841). + let menu_dismiss_press = app.ui.canvas_tool_menu_dismissed + || crate::canvas_tool_menu::menu_rect_if_open(app, &ctx).is_some_and(|r| { + ui.input(|i| i.pointer.press_origin()).is_some_and(|p| !r.contains(p)) + }); // Preferences › Tools › Enable Flick Panning: a Hand drag let go while moving glides on. let flick_id = egui::Id::unique(("pc-flick-pan", idx, primary, ctx.viewport_id())); let flick_on = app.session.prefs().tools.enable_flick_panning; - if let Some(d) = crate::flick_pan::frame(&ctx, flick_id, hand_pan && response.dragged() && !stroke_dismissal, response.drag_delta(), flick_on) { + if let Some(d) = crate::flick_pan::frame(&ctx, flick_id, hand_pan && response.dragged() && !stroke_dismissal && !menu_dismiss_press, response.drag_delta(), flick_on) { let d = xf.unmap_vec(d) / (view.zoom / ppp); if d.is_finite() { view.zoom_animating = false; @@ -855,7 +866,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: ctx.data_mut(|m| m.get_temp_mut_or_default::(flick_id).stop()); } } - if hand_pan && response.dragged() && !stroke_dismissal { + if hand_pan && response.dragged() && !stroke_dismissal && !menu_dismiss_press { let d = xf.unmap_vec(response.drag_delta()) / (view.zoom / ppp); view.center[0] -= d.x; view.center[1] -= d.y; @@ -889,15 +900,6 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: crate::paint_mouse::sync_tool_brush(app); let mut buttons = crate::paint_mouse::canvas_buttons(app, &response, tool); - // A press outside an open canvas tool menu dismisses it (`canvas_tool_menu::show`, after - // this input pass) and the whole gesture is consumed until its release, as in Photoshop: - // no tool press, stroke, drag or zoom step. The menu closes mid-frame (after this input - // pass), so the open-menu hit test covers the dismissal frame and the flag persists the - // block for the frames after it, until the release clear below the click handling. - let menu_dismiss_press = app.ui.canvas_tool_menu_dismissed - || crate::canvas_tool_menu::menu_rect_if_open(app, &ctx).is_some_and(|r| { - ui.input(|i| i.pointer.press_origin()).is_some_and(|p| !r.contains(p)) - }); if menu_dismiss_press { // Navigation and drags read `buttons` directly (zoom holds and drags, Rotate View): // starve them. The release click stays armed, so the click handling below consumes diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs index 1a1679e6c9..d72f3b1469 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs @@ -639,6 +639,50 @@ fn a_held_menu_dismissal_press_never_arms_the_zoom_hold() { assert_eq!(h.state().ui.views[0].zoom, zoom, "the dismissal release does not zoom either"); } +/// #9832 (CodeRabbit): while the dismissal press stays down, the temporary Hand (Space) and the +/// selected Hand must not pan either — the consumed gesture is inert until its release, and the +/// pans read `response.dragged()` directly, so they need the gate up front. +#[test] +fn a_held_menu_dismissal_press_cannot_pan_the_view() { + fn key(h: &mut Harness<'static, PhotocraftApp>, k: egui::Key, pressed: bool) { + h.event(egui::Event::Key { key: k, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }); + h.run_steps(1); + } + let mut h = zoom_harness(false); + let (zoom, center0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center); + let open_at = screen_of(h.state(), [300.0, 100.0]); + right_click(&mut h, open_at, Modifiers::NONE); + assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the view menu"); + // The dismissal press: the menu goes, and the button stays down. + let far = dismissal_point(&h); + h.event(egui::Event::PointerMoved(far)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu"); + // Hold Space: the temporary Hand arms, but dragging must not pan the view. + key(&mut h, egui::Key::Space, true); + assert_eq!(crate::input::hold_keys::held_tool(h.state(), &h.ctx), Some(crate::input::hold_keys::Temporary::Hand), "Space arms the temporary hand"); + h.event(egui::Event::PointerMoved(far + vec2(120.0, -60.0))); + h.run_steps(2); + h.event(egui::Event::PointerMoved(far + vec2(240.0, -120.0))); + h.run_steps(2); + assert_eq!(h.state().ui.views[0].center, center0, "a held dismissal press must not pan the view"); + assert_eq!(h.state().ui.views[0].zoom, zoom); + // Release both: an ordinary Hand drag pans again, the flag did not stick. + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + key(&mut h, egui::Key::Space, false); + h.state_mut().ui.tool = Tool::Hand; + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + h.event(egui::Event::PointerMoved(far + vec2(100.0, 50.0))); + h.run_steps(2); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + assert_ne!(h.state().ui.views[0].center, center0, "an ordinary Hand drag pans the view again"); +} + #[test] fn view_menu_zoom_in_keeps_the_clicked_point_under_the_pointer() { let mut app = zoom_app(400, 300); From b4f0bc042a7307a51a3bc1c87b51b39a8c4a21ca Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Sat, 7 Nov 2026 09:49:38 +0800 Subject: [PATCH 06/11] fix: keep Magnetic Lasso hover moves outside the click-only branch The merge of main (d453c7d12) moved the Magnetic Lasso's pointer-only hover block inside `if buttons.clicked`. `canvas_buttons` sets `clicked` from `response.clicked() || erase_click`, so on a pointer-only frame it is false and the block never ran: after the first fastening click, live edge tracking and automatic fastening froze until the next click. The base ran this block at a top-level `if`. Hoist it back above the click-only branch. A menu-dismissal gesture is still inert: the block is gated on `menu_dismiss_press`, the same state that starves the rest of the input pass and that the reviewer asked the dismissal suppression to use. Regressions, verified by reverting only canvas.rs: - `on_the_canvas_the_border_follows_the_hovering_pointer_and_keys_work` and `on_the_canvas_a_double_click_closes_the_border` pass on the merge base d453c7d12 and fail on the merged head (FredApps [P1], #9841). - new `on_the_canvas_hover_moves_survive_a_menu_dismissal_and_resume` covers the dismissal interaction: the hover is suppressed while the dismissal press is held and resumes on the next pointer move. --- crates/ui-egui/src/canvas.rs | 31 ++++++++++------ .../src/tools/magnetic_lasso_ui/tests.rs | 37 +++++++++++++++++++ 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index aa56bd6fad..9154b72e04 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1153,6 +1153,26 @@ fn handle_canvas_tool_clicks( let ppp = input.ppp; let zoom_out = input.zoom_out; let display_zoom = input.display_zoom; + // Magnetic Lasso: between clicks the border follows the pointer with the button up. This is a + // pointer-only gesture — `canvas_buttons` makes `clicked` false on frames without a button + // event — so it must stay outside the click-only branch below, or live edge tracking and + // automatic fastening freeze until the next click. A menu-dismissal gesture is inert, so the + // hover is suppressed with the same flag that starves the rest of the input pass (#9841). + if tool == Tool::MagneticLasso + && app.ui.magnetic.active() + && !input.menu_dismiss_press + && !(buttons.started || buttons.dragged || buttons.stopped) + && response.hovered() + { + let moves: Vec = ui.input(|i| i.events.iter().filter_map(|e| if let egui::Event::PointerMoved(p) = e { Some(*p) } else { None }).collect()); + app.defer_live_stroke = true; + for p in moves.into_iter().filter(|p| rect.contains(*p)) { + let d = xf.to_doc(p); + tool_event(app, ToolEvent::Move { x: d[0], y: d[1], pressure: app.stylus.pressure() }, mods); + } + app.defer_live_stroke = false; + crate::magnetic_lasso_ui::flush(app); + } if buttons.clicked && let Some(p) = response.interact_pointer_pos() { @@ -1212,17 +1232,6 @@ fn handle_canvas_tool_clicks( } } } - // Magnetic Lasso: between clicks the border follows the pointer with the button up. - if tool == Tool::MagneticLasso && app.ui.magnetic.active() && !(buttons.started || buttons.dragged || buttons.stopped) && response.hovered() { - let moves: Vec = ui.input(|i| i.events.iter().filter_map(|e| if let egui::Event::PointerMoved(p) = e { Some(*p) } else { None }).collect()); - app.defer_live_stroke = true; - for p in moves.into_iter().filter(|p| rect.contains(*p)) { - let d = xf.to_doc(p); - tool_event(app, ToolEvent::Move { x: d[0], y: d[1], pressure: app.stylus.pressure() }, mods); - } - app.defer_live_stroke = false; - crate::magnetic_lasso_ui::flush(app); - } // Move tool: a double-click on type edits it, as in Photoshop (#1132). Only the selected // Move tool, not ⌘ held over another tool; an open transform box keeps its double-click // (commit, below). diff --git a/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs b/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs index 11d5137621..73d325a506 100644 --- a/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs +++ b/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs @@ -381,6 +381,43 @@ fn on_the_canvas_the_border_follows_the_hovering_pointer_and_keys_work() { assert!((area - 5600.0).abs() < 120.0, "{area}"); } +/// #9841: the hover moves are a pointer-only gesture: they must keep running on frames with no +/// button event, and they must be suppressed while a menu-dismissal press is being consumed. +#[test] +fn on_the_canvas_hover_moves_survive_a_menu_dismissal_and_resume() { + let mut h = harness(); + ui_click(&mut h, 52.0, 37.0); + assert!(h.state().ui.magnetic.active()); + h.run_steps(2); + // A right-click opens the view menu without disturbing the border in progress. + let p = screen(&h, 90.0, 90.0); + h.event(egui::Event::PointerMoved(p)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the menu"); + // The dismissal press well clear of the menu: inert, and the pointer-only hover must not run. + let far = screen(&h, 12.0, 140.0); + h.event(egui::Event::PointerMoved(far)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu"); + let held = h.state().ui.magnetic.clone(); + h.event(egui::Event::PointerMoved(screen(&h, 100.0, 36.0))); + h.run_steps(2); + assert_eq!(h.state().ui.magnetic, held, "a held dismissal press must not track the pointer"); + // Released: the very next pointer move tracks again, with no button event at all. + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + ui_hover(&mut h, &[[52.0, 37.0], [100.0, 36.0]]); + let m = &h.state().ui.magnetic; + let end = m.live.last().or(m.path.last()).copied().unwrap(); + assert!((end[0] - 100.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover resumes after the dismissal: {end:?}"); +} + #[test] fn on_the_canvas_a_double_click_closes_the_border() { let mut h = harness(); From 9cdf6160b72aad54f9c344255b36459536bc14f6 Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Sat, 7 Nov 2026 10:45:01 +0800 Subject: [PATCH 07/11] contributors: credit Kaedo17 by the name on the GitHub profile Adds my own entry to contributors/people.toml, as AGENTS.md asks a contributor to do in their own PR. sync_github_name = true takes the display name from my public GitHub profile; the About window drops it until the maintainer's next contributors.py run marks the entry verified. --- contributors/people.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contributors/people.toml b/contributors/people.toml index ac36371f38..70c7075775 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -282,3 +282,6 @@ sync_github_name = false [people.jasallen] real_name = "Jason DeBoever" sync_github_name = true + +[people.Kaedo17] +sync_github_name = true From bfdf124639bec7946b2197fd51b87bbc4b3c2384 Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Sun, 8 Nov 2026 10:43:04 +0800 Subject: [PATCH 08/11] test: stage the dismissal gate the way the gesture actually holds it The re-merge to main (9ac3fa22b) broke this test's premise. Main gained `canvas_tool_menu::magnetic_drawing` (#11689): a right-click over a Magnetic Lasso border in progress opens no menu, on the canvas and through the control channel alike. So a menu can no longer be open over a live border, and the test's right-click setup asserted behaviour that is now deliberately gone. The `menu_dismiss_press` check on the hover block is therefore a guard rather than a sequence a pointer can reach. The test stages the dismissal state directly instead, with the button held: the flag is scoped to a held button (a frame with every button up clears it), so a pointer-up frame would clear it before the gate reads it and prove nothing. Holding the button also showed the guard does suppress the hover, which the pointer-up version silently did not. Two failures found while rebasing, both fixed here: - the obsolete right-click setup (this commit); - the pointer-up staging, which passed the flag only after the clear. --- .../src/tools/magnetic_lasso_ui/tests.rs | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs b/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs index e9cb10ceb6..db059edc3c 100644 --- a/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs +++ b/crates/ui-egui/src/tools/magnetic_lasso_ui/tests.rs @@ -418,41 +418,42 @@ fn on_the_canvas_the_border_follows_the_hovering_pointer_and_keys_work() { assert!((area - 5600.0).abs() < 120.0, "{area}"); } -/// #9841: the hover moves are a pointer-only gesture: they must keep running on frames with no -/// button event, and they must be suppressed while a menu-dismissal press is being consumed. +/// #9841: the hover moves are a pointer-only gesture. Two things must hold: they keep running on +/// frames with no button event at all (the freeze the main-merge regression reintroduced), and a +/// consumed menu-dismissal gesture must not track the pointer. +/// +/// A canvas menu cannot be open over a live border — `canvas_tool_menu::magnetic_drawing` refuses +/// one for a Magnetic Lasso border in progress (#11689), on the canvas and through the control +/// channel alike — so the `menu_dismiss_press` check on the hover block is a guard rather than a +/// sequence a pointer can reach. The dismissal state is staged directly here, with the button held +/// as the real gesture has it: the flag is scoped to a held button (a frame with every button up +/// clears it), so a pointer-up frame would clear it before the gate reads it and test nothing. #[test] fn on_the_canvas_hover_moves_survive_a_menu_dismissal_and_resume() { let mut h = harness(); ui_click(&mut h, 52.0, 37.0); assert!(h.state().ui.magnetic.active()); h.run_steps(2); - // A right-click opens the view menu without disturbing the border in progress. - let p = screen(&h, 90.0, 90.0); - h.event(egui::Event::PointerMoved(p)); - h.run_steps(1); - h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE }); - h.run_steps(1); - h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }); - h.run_steps(2); - assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the menu"); - // The dismissal press well clear of the menu: inert, and the pointer-only hover must not run. - let far = screen(&h, 12.0, 140.0); - h.event(egui::Event::PointerMoved(far)); - h.run_steps(1); - h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); - h.run_steps(1); - assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu"); - let held = h.state().ui.magnetic.clone(); - h.event(egui::Event::PointerMoved(screen(&h, 100.0, 36.0))); - h.run_steps(2); - assert_eq!(h.state().ui.magnetic, held, "a held dismissal press must not track the pointer"); - // Released: the very next pointer move tracks again, with no button event at all. - h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); - h.run_steps(2); + // Button up: the border follows the pointer with no button event at all. ui_hover(&mut h, &[[52.0, 37.0], [100.0, 36.0]]); let m = &h.state().ui.magnetic; let end = m.live.last().or(m.path.last()).copied().unwrap(); - assert!((end[0] - 100.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover resumes after the dismissal: {end:?}"); + assert!((end[0] - 100.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover tracks with the button up: {end:?}"); + // A consumed dismissal gesture with its button still down: the hover must not advance. + let far = screen(&h, 150.0, 130.0); + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + h.state_mut().ui.canvas_tool_menu_dismissed = true; + let held = h.state().ui.magnetic.clone(); + ui_hover(&mut h, &[[100.0, 36.0], [130.0, 36.0]]); + assert_eq!(h.state().ui.magnetic, held, "a consumed dismissal gesture must not track the pointer"); + // Released: the very next pointer move tracks again. + h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + ui_hover(&mut h, &[[130.0, 36.0], [120.0, 36.0]]); + let m = &h.state().ui.magnetic; + let end = m.live.last().or(m.path.last()).copied().unwrap(); + assert!((end[0] - 120.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover resumes once released: {end:?}"); } #[test] From 2bc47603c6b38698ba214dde40b42f68992c892e Mon Sep 17 00:00:00 2001 From: Kaedo17 Date: Sun, 8 Nov 2026 13:12:03 +0800 Subject: [PATCH 09/11] fix: consume the dismissal press before the Lasso reads it FredApps [P2] on bfdf12463: the Lasso reads its own raw pointer events (`lasso_ui::canvas_input` takes `ctx.input().events` directly), so the `buttons` starvation the other tools get never reaches it. A press that dismissed the canvas tool menu still drew a Lasso selection, leaving the shared selection-menu case of the dismissal fix incomplete. The Freeform Pen draws through the same dispatcher. Gate the dispatcher on `menu_dismiss_press`, as the Crop press above it is gated. The regression follows the reported case: right-click at document (300, 100), then left-press outside the menu at (50, 250) and drag through (50, 200), (150, 200), (150, 250), release. It asserts no drag is left behind, no selection and no history step, and that the next ordinary Lasso drag draws again. Fails on bfdf12463 at "the consumed gesture must draw no selection", passes here. --- crates/ui-egui/src/canvas.rs | 7 +++-- crates/ui-egui/src/tools/lasso_ui/tests.rs | 36 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 6ebd05ae0e..a5ebc9d9be 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -961,8 +961,11 @@ fn handle_canvas_tool_menus(app: &mut PhotocraftApp, input: &CanvasToolInput<'_> }; // The Lasso (and the Freeform Pen, which draws the same way) reads its own presses and // drops the moves of a drag it didn't start, so an open Free Transform box takes the - // usual drag path instead (#2153). - if crate::lasso_ui::owns(tool) && !transform_owns_pointer { + // usual drag path instead (#2153). It reads the raw pointer events straight from the + // context, so the `buttons` starvation above never reaches it: a press that dismisses the + // canvas tool menu would draw a selection. Gate the dispatcher itself, as the Crop press + // above is gated (#9841). + if crate::lasso_ui::owns(tool) && !transform_owns_pointer && !input.menu_dismiss_press { crate::lasso_ui::canvas_input(app, ctx, xf, response); (buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false); } diff --git a/crates/ui-egui/src/tools/lasso_ui/tests.rs b/crates/ui-egui/src/tools/lasso_ui/tests.rs index 816d661152..a568d102ae 100644 --- a/crates/ui-egui/src/tools/lasso_ui/tests.rs +++ b/crates/ui-egui/src/tools/lasso_ui/tests.rs @@ -524,3 +524,39 @@ fn alt_clicking_narrow_and_rotated_polygons_keeps_the_fourth_corner() { assert!(app.session.active().unwrap().doc.selection.is_some()); } } + +/// #9841: the Lasso reads its own raw pointer events (`lasso_ui::canvas_input`), so the +/// `Buttons` starvation the other tools get does not reach it. A press that dismisses the +/// canvas tool menu must not draw a Lasso selection, and the next ordinary drag must work. +#[test] +fn a_menu_dismissal_press_never_draws_a_lasso_selection() { + let mut h = harness(); + // Right-click on the canvas: the selection menu opens. + let menu_at = crate::canvas::ViewXform::active(h.state()).unwrap().to_screen(300.0, 100.0); + h.event(Event::PointerMoved(menu_at)); + h.run_steps(1); + h.event(Event::PointerButton { pos: menu_at, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE }); + h.run_steps(1); + h.event(Event::PointerButton { pos: menu_at, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the selection menu"); + let revision = h.state().session.active().unwrap().revision; + // The dismissal press and drag, well clear of the menu. + mouse(&mut h, "down", 50.0, 250.0, Modifiers::NONE); + assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu"); + mouse(&mut h, "move", 50.0, 200.0, Modifiers::NONE); + mouse(&mut h, "move", 150.0, 200.0, Modifiers::NONE); + mouse(&mut h, "move", 150.0, 250.0, Modifiers::NONE); + mouse(&mut h, "up", 150.0, 250.0, Modifiers::NONE); + h.run_steps(2); + assert!(h.state().drag.is_none(), "the consumed gesture must not leave a Lasso drag behind"); + assert!(h.state().session.active().unwrap().doc.selection.is_none(), "the consumed gesture must draw no selection"); + assert_eq!(h.state().session.active().unwrap().revision, revision, "and no history step"); + // The next ordinary drag draws one, so the guard did not stick. + mouse(&mut h, "down", 50.0, 50.0, Modifiers::NONE); + mouse(&mut h, "move", 90.0, 40.0, Modifiers::NONE); + mouse(&mut h, "move", 150.0, 60.0, Modifiers::NONE); + mouse(&mut h, "up", 150.0, 60.0, Modifiers::NONE); + h.run_steps(2); + assert!(h.state().session.active().unwrap().doc.selection.is_some(), "an ordinary Lasso drag draws again"); +} From adaba2a34e67d315aabb397a2ccb4375263aeaf3 Mon Sep 17 00:00:00 2001 From: Kaedo17 <92620393+Kaedo17@users.noreply.github.com> Date: Mon, 9 Nov 2026 12:45:29 +0800 Subject: [PATCH 10/11] style: split the glide-choice assignment for rustfmt cargo fmt --all -- --check on the merge commit flags only the glide_scroll_all assignment added by the conflict resolution: the merge produced it as one long line, and rustfmt wants the call on its own line. No behaviour change (cloutier, #9841). --- crates/ui-egui/src/canvas.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 0c96401fa7..c6ff22853f 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -2228,7 +2228,8 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect: let scroll_source = crate::scroll_all_windows::source(app, idx); // A glide keeps the drag's choice after Space, Shift or the button is let go; a menu-dismissal // press is no pan, so it neither arms the glide nor moves the other views. - let glide_scroll_all = crate::scroll_all_windows::glide_choice(&ctx, flick_id.with("scroll-all"), hand_drag && !stroke_dismissal && !menu_dismiss_press, scroll_all); + let glide_scroll_all = + crate::scroll_all_windows::glide_choice(&ctx, flick_id.with("scroll-all"), hand_drag && !stroke_dismissal && !menu_dismiss_press, scroll_all); if let Some(d) = crate::flick_pan::frame(&ctx, flick_id, hand_drag && !stroke_dismissal && !menu_dismiss_press, response.drag_delta(), flick_on) { let d = xf.unmap_vec(d) / (view.zoom / ppp); let before = view.center; From 51bf4680074a55dae06eda7ab9b88666a503e36e Mon Sep 17 00:00:00 2001 From: Kaedo17 <92620393+Kaedo17@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:16:50 +0800 Subject: [PATCH 11/11] contributors: keep davidvhk's name-sync setting in the table The earlier people.toml merge resolution inserted the new [people.Kaedo17] header between [people.davidvhk]'s real_name and its sync_github_name = true, so TOML parsed that setting as Kaedo17's and davidvhk silently lost theirs. Restore davidvhk's setting and keep Kaedo17 as its own block with its own sync_github_name = true (FredApps, #9841). Parsing base 9394960e4 and this tree side by side: the only difference is the added [people.Kaedo17] entry; every existing entry is unchanged. --- contributors/people.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contributors/people.toml b/contributors/people.toml index 643c08f544..81f432e436 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -314,6 +314,8 @@ sync_github_name = false [people.davidvhk] real_name = "David Vanhoucke" +sync_github_name = true + [people.Kaedo17] sync_github_name = true