From 2ea588d42ac6d669ff30e52c0396ffa09ff917b0 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Fri, 30 Oct 2026 21:12:07 +0100 Subject: [PATCH 1/5] Crop: Esc hides the crop frame until a press or re-picking the tool (#10370) Esc cancelled the crop but the next frame made the default frame again, so the borders never went away. Esc, the options bar's cancel and the crop menu's Cancel now hide the frame (crop_ui::dismiss); a press on the canvas draws a new one, and leaving and re-picking the tool brings the default frame back. Co-Authored-By: Claude Sonnet 5.5 --- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 2 +- crates/ui-egui/src/input/shortcuts.rs | 2 +- crates/ui-egui/src/panels/options_bar.rs | 2 +- crates/ui-egui/src/tools/crop_ui.rs | 21 ++++++++ crates/ui-egui/src/tools/crop_ui/tests.rs | 53 +++++++++++++++++++ 5 files changed, 77 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 9d5b84651f..b61afcc7f0 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -313,7 +313,7 @@ fn choose_crop(app: &mut PhotocraftApp, menu: &CanvasToolMenu, command: &str) -> use crate::crop_overlay::{CropOverlay, OverlayShow}; use crate::crop_presets::{Choice, apply_choice}; match command { - CROP_CANCEL => crate::crop_ui::cancel(app), + CROP_CANCEL => crate::crop_ui::dismiss(app), CROP_COMMIT => crate::canvas::commit_crop(app), CROP_NEW => apply_choice(app, Choice::New), CROP_DELETE => apply_choice(app, Choice::Delete), diff --git a/crates/ui-egui/src/input/shortcuts.rs b/crates/ui-egui/src/input/shortcuts.rs index e6a20bae55..277ca0af29 100644 --- a/crates/ui-egui/src/input/shortcuts.rs +++ b/crates/ui-egui/src/input/shortcuts.rs @@ -819,7 +819,7 @@ fn handle_registry_and_tool_keys(app: &mut PhotocraftApp, ctx: &egui::Context, f app.ui.polygon.clear(); app.ui.polygon_mode.clear(); app.ui.polygon_doc = None; - crate::crop_ui::cancel(app); + crate::crop_ui::dismiss(app); return true; } } diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index e03fa24e7a..eba8fd1d24 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -539,7 +539,7 @@ fn selection_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: crate::canvas::commit_crop(app); } if icons::button(ui, "ban", 26.0, false, tl!("Cancel current crop operation (Esc)")).clicked() { - crate::crop_ui::cancel(app); + crate::crop_ui::dismiss(app); } }); } diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index 3a05ba2cc7..350296a690 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -51,6 +51,10 @@ pub struct CropState { pub default_frame: bool, /// The document (index and size) the default frame was made for. frame_for: Option<(usize, u32, u32)>, + /// The document (index and size) whose frame Esc (or the options bar's cancel) hid: with the + /// Crop tool still picked no default frame is made for it until a press on the canvas, or + /// leaving and re-picking the tool, as in Photoshop (#10370). + dismissed: Option<(usize, u32, u32)>, /// The frame is being edited (pressed since it was made): the canvas shows what lies past it. pub editing: bool, /// The document the pending frame (or gesture) belongs to ([`cancel_stale`], #1918). @@ -350,6 +354,7 @@ pub fn ensure_frame(app: &mut PhotocraftApp) { fn frame(app: &mut PhotocraftApp) { if app.ui.tool != Tool::Crop { app.crop.editing = false; + app.crop.dismissed = None; crate::crop_straighten::reset(app); // Leaving the tool drops an untouched default frame and, as in Photoshop, commits a // drawn one (#3368). @@ -377,6 +382,11 @@ fn frame(app: &mut PhotocraftApp) { if app.ui.crop_rect.is_some() || app.crop.drag.is_some() { return; } + // Esc hid the frame: it stays hidden for this document until the next press. + if key.is_some() && app.crop.dismissed == key { + return; + } + app.crop.dismissed = None; let Some(st) = app.session.active() else { return }; let canvas = st.doc.bounds(); // Computed once per new frame, not per frame drawn. @@ -433,6 +443,16 @@ pub fn cancel(app: &mut PhotocraftApp) { crate::crop_straighten::reset(app); } +/// Esc or the options bar's cancel: [`cancel`], then, with the Crop tool picked, the frame stays +/// hidden (no new default frame) until a press on the canvas or re-picking the tool, as in +/// Photoshop (#10370). +pub fn dismiss(app: &mut PhotocraftApp) { + cancel(app); + if app.ui.tool == Tool::Crop { + app.crop.dismissed = app.session.active_index().zip(app.session.active()).map(|(i, st)| (i, st.doc.size.width, st.doc.size.height)); + } +} + /// Drop the box's own Undo/Redo (leaving the tool, cancelling or committing a crop). pub fn clear_history(app: &mut PhotocraftApp) { app.crop.undo.clear(); @@ -815,6 +835,7 @@ fn straighten(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers, p: [f64; /// Starts the drag a press at `p` selects: resize, move, turn or draw. fn begin_drag(app: &mut PhotocraftApp, p: [f64; 2]) { + app.crop.dismissed = None; claim(app); app.crop.editing = true; app.crop.press_step = Some(step_of(app)); diff --git a/crates/ui-egui/src/tools/crop_ui/tests.rs b/crates/ui-egui/src/tools/crop_ui/tests.rs index 6fba4e57d4..86c67c42bf 100644 --- a/crates/ui-egui/src/tools/crop_ui/tests.rs +++ b/crates/ui-egui/src/tools/crop_ui/tests.rs @@ -1144,3 +1144,56 @@ fn readout_shows_the_frame_size_while_drawing_or_resizing() { assert_eq!(frame_size([f64::NAN, 0.0, 1.0, 1.0]), None); assert_eq!(frame_size([-f64::MAX, 0.0, f64::MAX, 1.0]), None); } + +/// Esc through the real shortcut handler. +fn press_esc(app: &mut PhotocraftApp) { + let key = egui::Key::Escape; + let input = egui::RawInput { + focused: true, + events: vec![egui::Event::Key { key, physical_key: Some(key), pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }], + ..Default::default() + }; + egui::Context::default().run_ui(input, |ui| crate::shortcuts::handle(app, ui.ctx())).textures_delta.clear(); +} + +#[test] +fn esc_hides_the_frame_until_a_press_or_re_picking_the_tool() { + // #10370: Esc cancelled the crop but the next frame made the default frame again. + for classic in [false, true] { + let mut app = app(SampleType::U8); + app.ui.tool_options.crop_shield.classic_mode = classic; + ensure_frame(&mut app); + assert!(app.ui.crop_rect.is_some() && app.crop.default_frame); + // The untouched default frame: Esc hides it, and it stays hidden frame after frame. + press_esc(&mut app); + for _ in 0..3 { + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None, "classic={classic}"); + } + // A press on the canvas draws a new frame. + drag(&mut app, &[[50.0, 20.0], [80.0, 40.0], [120.0, 70.0]], NONE); + assert_eq!(app.ui.crop_rect, Some([50.0, 20.0, 120.0, 70.0])); + // A drawn frame: Esc hides it too, and crops nothing. + press_esc(&mut app); + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); + assert_eq!(app.session.active().unwrap().doc.size, Size::new(200, 100)); + // Re-picking the tool brings the default frame back. + app.ui.tool = Tool::Brush; + ensure_frame(&mut app); + app.ui.tool = Tool::Crop; + ensure_frame(&mut app); + assert!(app.ui.crop_rect.is_some() && app.crop.default_frame); + // The options bar's cancel hides it as well; a plain cancel (stale document) does not. + dismiss(&mut app); + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); + app.ui.tool = Tool::Brush; + ensure_frame(&mut app); + app.ui.tool = Tool::Crop; + ensure_frame(&mut app); + cancel(&mut app); + ensure_frame(&mut app); + assert!(app.ui.crop_rect.is_some()); + } +} From 9ba6035d433459eb1a38e1b720757d0c6cb70e23 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sat, 31 Oct 2026 00:37:50 +0100 Subject: [PATCH 2/5] Crop: key the Esc dismissal by document id, and end it on a Straighten press (#10370) Review follow-ups: the dismissal was keyed by tab index, so closing the dismissed document could hide the frame of a same-size tab that took its index; and a press taken by Straighten skipped `begin_drag`, leaving the frame hidden after a click too short to level anything. Regression tests for both. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/crop_ui.rs | 21 +++++++++++---- crates/ui-egui/src/tools/crop_ui/tests.rs | 33 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index 350296a690..dce46b3c2f 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -51,10 +51,11 @@ pub struct CropState { pub default_frame: bool, /// The document (index and size) the default frame was made for. frame_for: Option<(usize, u32, u32)>, - /// The document (index and size) whose frame Esc (or the options bar's cancel) hid: with the + /// The document (id and size) whose frame Esc (or the options bar's cancel) hid: with the /// Crop tool still picked no default frame is made for it until a press on the canvas, or - /// leaving and re-picking the tool, as in Photoshop (#10370). - dismissed: Option<(usize, u32, u32)>, + /// leaving and re-picking the tool, as in Photoshop (#10370). Keyed by id, not tab index, so + /// closing it never hides the frame of the tab that takes its place. + dismissed: Option<(photocraft_doc::DocId, u32, u32)>, /// The frame is being edited (pressed since it was made): the canvas shows what lies past it. pub editing: bool, /// The document the pending frame (or gesture) belongs to ([`cancel_stale`], #1918). @@ -383,7 +384,7 @@ fn frame(app: &mut PhotocraftApp) { return; } // Esc hid the frame: it stays hidden for this document until the next press. - if key.is_some() && app.crop.dismissed == key { + if app.crop.dismissed.is_some() && app.crop.dismissed == dismiss_key(app) { return; } app.crop.dismissed = None; @@ -449,10 +450,15 @@ pub fn cancel(app: &mut PhotocraftApp) { pub fn dismiss(app: &mut PhotocraftApp) { cancel(app); if app.ui.tool == Tool::Crop { - app.crop.dismissed = app.session.active_index().zip(app.session.active()).map(|(i, st)| (i, st.doc.size.width, st.doc.size.height)); + app.crop.dismissed = dismiss_key(app); } } +/// The active document's identity for [`CropState::dismissed`]. +fn dismiss_key(app: &PhotocraftApp) -> Option<(photocraft_doc::DocId, u32, u32)> { + app.session.active().map(|st| (st.doc.id, st.doc.size.width, st.doc.size.height)) +} + /// Drop the box's own Undo/Redo (leaving the tool, cancelling or committing a crop). pub fn clear_history(app: &mut PhotocraftApp) { app.crop.undo.clear(); @@ -816,6 +822,11 @@ fn straighten(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers, p: [f64; if !crate::crop_straighten::pointer(app, ev, mods) { return false; } + // A press it takes ends an Esc dismissal like any other press, even when the line is too + // short to turn the frame (#10370). + if matches!(ev, ToolEvent::Down { .. }) { + app.crop.dismissed = None; + } claim(app); // Default mode: the image turns so the line ends up level. // The turn is one box Undo step, like any other frame gesture. diff --git a/crates/ui-egui/src/tools/crop_ui/tests.rs b/crates/ui-egui/src/tools/crop_ui/tests.rs index 86c67c42bf..3f5f537390 100644 --- a/crates/ui-egui/src/tools/crop_ui/tests.rs +++ b/crates/ui-egui/src/tools/crop_ui/tests.rs @@ -1197,3 +1197,36 @@ fn esc_hides_the_frame_until_a_press_or_re_picking_the_tool() { assert!(app.ui.crop_rect.is_some()); } } + +#[test] +fn closing_a_dismissed_document_never_hides_the_next_tabs_frame() { + // #10370 review: the dismissal was keyed by tab index, so a same-size tab moving into the + // closed one's index kept its frame hidden. + let mut app = app(SampleType::U8); + let doc = Document::with_background("other", Size::new(200, 100), ColorMode::Rgb, SampleType::U8, Color::WHITE); + app.session.add_document(doc, None); + assert!(app.session.set_active(0)); + ensure_frame(&mut app); + press_esc(&mut app); + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); + assert!(app.session.close(0).is_some()); + assert_eq!(app.session.active_index(), Some(0)); + ensure_frame(&mut app); + assert!(app.ui.crop_rect.is_some() && app.crop.default_frame); +} + +#[test] +fn a_straighten_press_ends_the_dismissal() { + // #10370 review: a press taken by Straighten skipped `begin_drag`, which ends the dismissal, + // so a click too short to level anything left the frame hidden. + let mut app = app(SampleType::U8); + ensure_frame(&mut app); + press_esc(&mut app); + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); + app.crop.straighten.armed = true; + drag(&mut app, &[[50.0, 20.0], [50.5, 20.0]], NONE); + ensure_frame(&mut app); + assert!(app.ui.crop_rect.is_some()); +} From d92ee2f8205e4bb89ce760206bb405b33e8c13de Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:08:00 +0100 Subject: [PATCH 3/5] docs: tidy comments (review) Co-Authored-By: Claude Sonnet 5.5 --- crates/ui-egui/src/tools/crop_ui.rs | 7 +++---- crates/ui-egui/src/tools/crop_ui/tests.rs | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index dce46b3c2f..c9dcdc9bc6 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -51,10 +51,9 @@ pub struct CropState { pub default_frame: bool, /// The document (index and size) the default frame was made for. frame_for: Option<(usize, u32, u32)>, - /// The document (id and size) whose frame Esc (or the options bar's cancel) hid: with the - /// Crop tool still picked no default frame is made for it until a press on the canvas, or - /// leaving and re-picking the tool, as in Photoshop (#10370). Keyed by id, not tab index, so - /// closing it never hides the frame of the tab that takes its place. + /// The document (id and size) whose frame [`dismiss`] hid: no default frame is made for it while + /// this matches. Keyed by id, not tab index, so closing it never hides the frame of the tab that + /// takes its place. dismissed: Option<(photocraft_doc::DocId, u32, u32)>, /// The frame is being edited (pressed since it was made): the canvas shows what lies past it. pub editing: bool, diff --git a/crates/ui-egui/src/tools/crop_ui/tests.rs b/crates/ui-egui/src/tools/crop_ui/tests.rs index 3f5f537390..3b06b80cd8 100644 --- a/crates/ui-egui/src/tools/crop_ui/tests.rs +++ b/crates/ui-egui/src/tools/crop_ui/tests.rs @@ -1200,8 +1200,7 @@ fn esc_hides_the_frame_until_a_press_or_re_picking_the_tool() { #[test] fn closing_a_dismissed_document_never_hides_the_next_tabs_frame() { - // #10370 review: the dismissal was keyed by tab index, so a same-size tab moving into the - // closed one's index kept its frame hidden. + // A same-size tab that takes the closed document's index must still show its frame. let mut app = app(SampleType::U8); let doc = Document::with_background("other", Size::new(200, 100), ColorMode::Rgb, SampleType::U8, Color::WHITE); app.session.add_document(doc, None); @@ -1218,8 +1217,8 @@ fn closing_a_dismissed_document_never_hides_the_next_tabs_frame() { #[test] fn a_straighten_press_ends_the_dismissal() { - // #10370 review: a press taken by Straighten skipped `begin_drag`, which ends the dismissal, - // so a click too short to level anything left the frame hidden. + // Straighten takes the press before `begin_drag`; a click too short to level anything still + // ends the dismissal. let mut app = app(SampleType::U8); ensure_frame(&mut app); press_esc(&mut app); From 48dc361afa396d1d5e57de59d307dedca1e7983e Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sun, 1 Nov 2026 11:52:17 +0100 Subject: [PATCH 4/5] test(crop): menu Cancel hides the frame like Esc; leaving the tool and undo after Esc (review) Co-Authored-By: Claude Opus 5.5 --- .../src/canvas/canvas_tool_menu/tests.rs | 4 ++++ crates/ui-egui/src/tools/crop_ui/tests.rs | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) 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 6f8d0a3aa8..760683b020 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs @@ -1217,4 +1217,8 @@ fn crop_menu_rows_act_like_the_options_bar() { reopen(&mut app); choose(&mut app, &ctx, CROP_CANCEL); assert!(!crate::crop_ui::pending(&app)); + // ...and, as Esc does, hides the frame without cropping (#10370). + crate::crop_ui::ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); + assert_eq!(app.session.active().unwrap().doc.size, size); } diff --git a/crates/ui-egui/src/tools/crop_ui/tests.rs b/crates/ui-egui/src/tools/crop_ui/tests.rs index 3b06b80cd8..16a9121ce9 100644 --- a/crates/ui-egui/src/tools/crop_ui/tests.rs +++ b/crates/ui-egui/src/tools/crop_ui/tests.rs @@ -1178,9 +1178,10 @@ fn esc_hides_the_frame_until_a_press_or_re_picking_the_tool() { ensure_frame(&mut app); assert_eq!(app.ui.crop_rect, None); assert_eq!(app.session.active().unwrap().doc.size, Size::new(200, 100)); - // Re-picking the tool brings the default frame back. + // Re-picking the tool brings the default frame back. Leaving it after Esc crops nothing. app.ui.tool = Tool::Brush; ensure_frame(&mut app); + assert_eq!(app.session.active().unwrap().doc.size, Size::new(200, 100), "classic={classic}"); app.ui.tool = Tool::Crop; ensure_frame(&mut app); assert!(app.ui.crop_rect.is_some() && app.crop.default_frame); @@ -1229,3 +1230,23 @@ fn a_straighten_press_ends_the_dismissal() { ensure_frame(&mut app); assert!(app.ui.crop_rect.is_some()); } + +#[test] +fn undoing_a_crop_after_esc_brings_the_frame_back() { + // Esc crops nothing, so it adds no step; an Undo that changes the canvas size shows a frame for it. + let mut app = app(SampleType::U8); + ensure_frame(&mut app); + drag(&mut app, &[[20.0, 10.0], [70.0, 30.0], [120.0, 60.0]], NONE); + crate::canvas::commit_crop(&mut app); + assert_eq!(app.session.active().unwrap().doc.size, Size::new(100, 50)); + ensure_frame(&mut app); + let steps = app.session.active().unwrap().history.entries().len(); + press_esc(&mut app); + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); + assert_eq!(app.session.active().unwrap().history.entries().len(), steps); + assert!(app.session.undo()); + assert_eq!(app.session.active().unwrap().doc.size, Size::new(200, 100)); + ensure_frame(&mut app); + assert!(app.ui.crop_rect.is_some() && app.crop.default_frame); +} From 4a591d66288990f60daa21a7a6fb8573274f59e4 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Mon, 2 Nov 2026 00:15:14 +0100 Subject: [PATCH 5/5] test(crop): an undo that keeps the canvas size leaves the Esc-hidden frame hidden (review) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/crop_ui/tests.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/ui-egui/src/tools/crop_ui/tests.rs b/crates/ui-egui/src/tools/crop_ui/tests.rs index 16a9121ce9..e0bcb7d3ea 100644 --- a/crates/ui-egui/src/tools/crop_ui/tests.rs +++ b/crates/ui-egui/src/tools/crop_ui/tests.rs @@ -1250,3 +1250,18 @@ fn undoing_a_crop_after_esc_brings_the_frame_back() { ensure_frame(&mut app); assert!(app.ui.crop_rect.is_some() && app.crop.default_frame); } + +#[test] +fn an_undo_that_keeps_the_canvas_size_leaves_the_frame_hidden() { + // Only a size change brings the frame back: undoing an edit that keeps the size doesn't. + let mut app = app(SampleType::U8); + app.run("image.adjustments.invert", json!({})).unwrap(); + ensure_frame(&mut app); + press_esc(&mut app); + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); + assert!(app.session.undo()); + assert_eq!(app.session.active().unwrap().doc.size, Size::new(200, 100)); + ensure_frame(&mut app); + assert_eq!(app.ui.crop_rect, None); +}