collective

Browse / github.com/storytold/photocraft / patch

Crop: H and P pick the Hand and Pen tools over the default frame (#9731)

Hand tool shortcut (H) stops working after committing a crop Steps to reproduce 1. Open an image. 2. Select the Crop tool using the toolbar or C. 3. Drag any edge of the crop box. 4. Press Enter to commit the crop. 5. Press H to activate the Hand tool. Expected behavior Pressing H should activate the Hand tool immediately after committing a crop. Actual behavior The H shortcut stops responding after the crop is committed. Pressing H does nothing.

Status
open
Score
0.00
Adopters
0 other operators
Author
Luis-0508 (imported from pull request #9855, open)
Base
7ac7b8b106acccf6826d45ed5c9e481dfe341035
Size
+37 −7 in 2 files
Review
pending
Shared
2026-10-28
Id
da8f4253a8615004ebcfc6c6

How it went

No other operator has reported using it yet.

Diff

raw · crates/ui-egui/src/tools/crop_mode/tests.rs crates/ui-egui/src/tools/crop_shield.rs

diff --git a/crates/ui-egui/src/tools/crop_mode/tests.rs b/crates/ui-egui/src/tools/crop_mode/tests.rs--- a/crates/ui-egui/src/tools/crop_mode/tests.rs+++ b/crates/ui-egui/src/tools/crop_mode/tests.rs@@ -537,7 +537,7 @@ fn arrows_nudge_the_image_shift_by_ten_and_x_recentres() { #[test] fn classic_mode_shows_the_cropped_area_and_h_does_nothing() {     let mut app = app();-    crate::crop_ui::ensure_frame(&mut app);+    with_frame(&mut app);     app.ui.tool_options.crop_shield.show_cropped_area = false;     assert!(crate::crop_shield::hides_outside(&app));     app.ui.tool_options.crop_shield.classic_mode = true;@@ -554,9 +554,9 @@ fn classic_mode_shows_the_cropped_area_and_h_does_nothing() { }  #[test]-fn p_toggles_classic_mode_while_the_crop_tool_shows_a_box() {+fn p_toggles_classic_mode_while_a_crop_is_in_progress() {     let mut app = app();-    crate::crop_ui::ensure_frame(&mut app);+    with_frame(&mut app);     let press = |app: &mut PhotocraftApp| {         let ctx = egui::Context::default();         ctx.input_mut(|i| i.events.push(egui::Event::Key { key: egui::Key::P, physical_key: None, pressed: true, repeat: false, modifiers: NONE }));@@ -579,6 +579,26 @@ fn p_toggles_classic_mode_while_the_crop_tool_shows_a_box() {     assert!(!classic(&app)); } +/// After a commit the tool shows its untouched default frame again: H and P are the Hand and Pen+/// keys there, as when the tool is picked, not Show Cropped Area and Classic Mode (#9731, #6536).+#[test]+fn h_and_p_pick_their_tools_over_the_default_frame_after_a_commit() {+    for (k, tool) in [(egui::Key::H, Tool::Hand), (egui::Key::P, Tool::Pen)] {+        let mut app = app();+        with_frame(&mut app);+        key(&mut app, egui::Key::Enter, NONE);+        assert_eq!(app.session.active().map(|st| st.doc.size), Some(Size::new(60, 40)), "the crop committed");+        crate::crop_ui::ensure_frame(&mut app);+        assert!(app.ui.crop_rect.is_some() && app.crop.default_frame, "the default frame is back");+        key(&mut app, k, NONE);+        assert_eq!(app.ui.tool, tool, "{k:?}");+        let s = &app.ui.tool_options.crop_shield;+        assert!(s.show_cropped_area && !s.classic_mode, "{k:?} changed no crop option");+        crate::crop_ui::ensure_frame(&mut app);+        assert!(app.ui.crop_rect.is_none(), "leaving the tool drops the default frame");+    }+}+ #[test] fn straighten_turns_the_image_so_the_line_is_level_on_screen() {     let mut app = app();diff --git a/crates/ui-egui/src/tools/crop_shield.rs b/crates/ui-egui/src/tools/crop_shield.rs--- a/crates/ui-egui/src/tools/crop_shield.rs+++ b/crates/ui-egui/src/tools/crop_shield.rs@@ -120,11 +120,13 @@ pub fn hides_outside(app: &PhotocraftApp) -> bool {     app.ui.tool == Tool::Crop && app.ui.crop_rect.is_some() && !app.ui.tool_options.crop_shield.shows_cropped_area() } -/// H with the Crop tool showing a box and no drag in progress toggles Show Cropped Area (in+/// H with a crop in progress (a frame drawn or changed) and no drag toggles Show Cropped Area (in /// Classic Mode, where the option is greyed out, H is taken and does nothing), and P Use Classic-/// Mode. Returns true when a key was used; otherwise H stays the Hand tool key and P the Pen's.+/// Mode. Returns true when a key was used; otherwise H stays the Hand tool key and P the Pen's,+/// also over the untouched default frame the tool shows when picked or after a commit (#6536,+/// #9731). pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {-    if app.ui.tool != Tool::Crop || app.ui.crop_rect.is_none() || app.crop.drag.is_some() {+    if app.ui.tool != Tool::Crop || app.ui.crop_rect.is_none() || app.crop.default_frame || app.crop.drag.is_some() {         return false;     }     if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::H)) {@@ -335,8 +337,10 @@ mod tests {     }      #[test]-    fn h_toggles_show_cropped_area_while_the_crop_tool_shows_a_box() {+    fn h_toggles_show_cropped_area_while_a_crop_is_in_progress() {         let mut app = crop_app();+        app.ui.crop_rect = Some([20.0, 10.0, 120.0, 90.0]);+        app.crop.default_frame = false;         assert!(!hides_outside(&app));         press_h(&mut app);         assert_eq!(app.ui.tool, Tool::Crop, "H doesn't switch to the Hand tool");@@ -354,6 +358,12 @@ mod tests {         press_h(&mut app);         assert_eq!(app.ui.tool, Tool::Hand);         assert!(app.ui.tool_options.crop_shield.show_cropped_area);+        // The untouched default frame (#9731).+        let mut app = crop_app();+        assert!(app.crop.default_frame);+        press_h(&mut app);+        assert_eq!(app.ui.tool, Tool::Hand);+        assert!(app.ui.tool_options.crop_shield.show_cropped_area);         // Another tool.         let mut app = crop_app();         app.ui.tool = Tool::Brush;