PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Open the selection menu on a Quick Selection right-click (#7268)
Hector Villarreal0c27aea23a93
diff --git a/crates/ui-egui/src/canvas_menu_tests.rs b/crates/ui-egui/src/canvas_menu_tests.rsindex 839dc1f76..2e211ca08 100644--- a/crates/ui-egui/src/canvas_menu_tests.rs+++ b/crates/ui-egui/src/canvas_menu_tests.rs@@ -119,7 +119,18 @@ fn check_reopening(tool: Tool, modifiers: Modifiers, popup: Popup) {#[test]fn secondary_taps_keep_selection_menus_open() {- for tool in [Tool::RectMarquee, Tool::EllipseMarquee, Tool::Lasso, Tool::PolygonLasso, Tool::MagneticLasso, Tool::MagicWand, Tool::ObjectSelection] {+ // Quick Selection too, though it has a brush: Photoshop's right-click there is the selection+ // menu (#7268), the brush is set from the options bar.+ for tool in [+ Tool::RectMarquee,+ Tool::EllipseMarquee,+ Tool::Lasso,+ Tool::PolygonLasso,+ Tool::MagneticLasso,+ Tool::MagicWand,+ Tool::ObjectSelection,+ Tool::QuickSelection,+ ] {check_reopening(tool, Modifiers::NONE, Popup::Tool);}}@@ -229,7 +240,8 @@ fn control_channel_opening_uses_the_same_dismissal_guard() {(Tool::RectMarquee, Popup::Tool, true),(Tool::Brush, Popup::Brush, false),(Tool::Eraser, Popup::Brush, false),- (Tool::QuickSelection, Popup::Brush, false),+ // Its right-click is the selection menu (#7268).+ (Tool::QuickSelection, Popup::Tool, false),] {for scale in [1.0, 2.0] {let mut h = harness(tool, true, scale);@@ -266,14 +278,14 @@ fn control_channel_right_click_on_committed_type_opens_the_type_layer_menu() {#[test]fn brush_picker_taps_preserve_pixels_selection_and_history_after_reopening() {- for tool in [Tool::Brush, Tool::Eraser, Tool::QuickSelection] {+ for tool in [Tool::Brush, Tool::Eraser] {check_reopening(tool, Modifiers::NONE, Popup::Brush);}}#[test]fn brush_chip_toggles_after_canvas_and_control_opening() {- for tool in [Tool::Brush, Tool::Eraser, Tool::QuickSelection] {+ for tool in [Tool::Brush, Tool::Eraser] {for scale in [1.0, 2.0] {let mut h = harness(tool, true, scale);let before = document_state(&h);@@ -299,6 +311,27 @@ fn brush_chip_toggles_after_canvas_and_control_opening() {}}+/// #7268: the Quick Selection tool's brush chip still opens and closes the Brush Preset picker;+/// only its canvas right-click is the selection menu.+#[test]+fn quick_selection_chip_toggles_the_picker_and_right_click_opens_the_selection_menu() {+ let mut h = harness(Tool::QuickSelection, true, 1.0);+ let before = document_state(&h);+ for _ in 0..2 {+ h.get_by_label(crate::i18n::t("Brush Preset picker")).click();+ h.run_steps(3);+ assert!(h.state().ui.brush_picker.is_some(), "the chip opens the picker");+ h.get_by_label(crate::i18n::t("Brush Preset picker")).click();+ h.run_steps(3);+ assert!(h.state().ui.brush_picker.is_none(), "the chip closes it");+ }+ let at = fractional_point(&h, 1.0);+ tap(&mut h, at, Modifiers::NONE, true);+ assert!(h.state().ui.brush_picker.is_none(), "no picker on a right-click");+ assert!(h.state().ui.canvas_tool_menu.as_ref().is_some_and(|m| m.has_selection), "the selection menu");+ assert!(document_state(&h) == before);+}+#[test]fn brush_preset_menu_action_outside_the_picker_keeps_it_open() {let mut h = harness(Tool::Brush, true, 1.0);diff --git a/crates/ui-egui/src/canvas_tool_menu.rs b/crates/ui-egui/src/canvas_tool_menu.rsindex f7f9892d2..024a81c1b 100644--- a/crates/ui-egui/src/canvas_tool_menu.rs+++ b/crates/ui-egui/src/canvas_tool_menu.rs@@ -315,6 +315,9 @@ pub fn applies(tool: Tool) -> bool {| Tool::MagneticLasso| Tool::MagicWand| Tool::ObjectSelection+ // Its brush is set from the options bar's chip; the canvas right-click is the+ // selection menu, as in Photoshop (#7268).+ | Tool::QuickSelection) || path_menu(tool)}diff --git a/crates/ui-egui/src/paint_mouse.rs b/crates/ui-egui/src/paint_mouse.rsindex a45c016c5..43b10d2b2 100644--- a/crates/ui-egui/src/paint_mouse.rs+++ b/crates/ui-egui/src/paint_mouse.rs@@ -86,11 +86,17 @@ pub struct Buttons {pub clicked: bool,}-/// Tools whose right-click opens the Brush Preset picker (those with the options-bar brush chip).+/// Tools with the options-bar brush chip, which opens the Brush Preset picker.pub fn has_brush_picker(tool: Tool) -> bool {tool.is_brushlike() || tool == Tool::QuickSelection}+/// Tools whose canvas right-click opens the Brush Preset picker: the painting tools. The Quick+/// Selection tool has the picker too, but its right-click opens the selection menu (#7268).+pub fn right_click_picker(tool: Tool) -> bool {+ has_brush_picker(tool) && !crate::canvas_tool_menu::applies(tool)+}+/// Does a right-button drag with `tool` erase (rather than open the picker)?pub fn right_erases(app: &PhotocraftApp, tool: Tool) -> bool {matches!(tool, Tool::Brush | Tool::Eraser) && app.session.prefs().tools.right_click_with_painting_tools == RightClickPaint::Erase@@ -119,7 +125,7 @@ pub fn canvas_buttons(app: &mut PhotocraftApp, response: &Response, tool: Tool)if right_click&& !erase&& !layer_menu- && has_brush_picker(tool)+ && right_click_picker(tool)&& let Some(p) = response.interact_pointer_pos(){crate::brush_picker::open(&mut app.ui, &response.ctx, [p.x, p.y]);@@ -149,7 +155,7 @@ pub fn pointer_secondary(app: &mut PhotocraftApp, ctx: &egui::Context, down: booapp.secondary_erase = down;return true;}- if down && has_brush_picker(tool) {+ if down && right_click_picker(tool) {crate::brush_picker::open(&mut app.ui, ctx, at);}false