Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Esc leaves full screen with the Crop tool showing its default frame (#7315) (#7350)

MarekSpodBiedryc8c651c413cd
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index 99613d5a2..bfa1904c4 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -627,7 +627,10 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
}
return;
}
- if pressed(Key::Escape) {
+ // In a full screen mode, the Crop tool's untouched default frame (Straighten off) has nothing to cancel: cancelling only
+ // makes the next one, so Esc goes on to leave full screen (#7315).
+ let untouched = app.ui.view.screen_mode != "standard" && app.ui.polygon.is_empty() && app.crop.default_frame && !crate::crop_straighten::mode(app);
+ if !untouched && pressed(Key::Escape) {
app.ui.polygon.clear();
app.ui.polygon_mode.clear();
crate::crop_ui::cancel(app);
diff --git a/crates/ui-egui/src/view_cmds/tests.rs b/crates/ui-egui/src/view_cmds/tests.rs
index 1abe86355..9361e5125 100644
--- a/crates/ui-egui/src/view_cmds/tests.rs
+++ b/crates/ui-egui/src/view_cmds/tests.rs
@@ -500,6 +500,29 @@ fn press_esc(app: &mut PhotocraftApp, ctx: &egui::Context) {
ctx.run_ui(input, |ui| crate::shortcuts::handle(app, ui.ctx())).textures_delta.clear();
}
+#[test]
+fn esc_leaves_full_screen_with_the_crop_tool_showing_its_default_frame() {
+ let (mut app, ctx) = app_with(1);
+ app.ui.tool = crate::Tool::Crop;
+ crate::crop_ui::ensure_frame(&mut app);
+ assert!(app.ui.crop_rect.is_some() && app.crop.default_frame);
+ for mode in ["fullScreen", "fullScreenWithMenuBar"] {
+ menu(&mut app, &ctx, &format!("view.screenMode.{mode}"), json!({})).unwrap();
+ press_esc(&mut app, &ctx);
+ assert_eq!(app.ui.view.screen_mode, "standard", "{mode}");
+ assert!(app.ui.crop_rect.is_some() && app.crop.default_frame, "{mode}: the default frame stays");
+ }
+ // With Straighten armed, Esc drops it first and the mode stays.
+ menu(&mut app, &ctx, "view.screenMode.fullScreen", json!({})).unwrap();
+ app.crop.straighten.armed = true;
+ press_esc(&mut app, &ctx);
+ assert!(!app.crop.straighten.armed);
+ assert_eq!(app.ui.view.screen_mode, "fullScreen");
+ crate::crop_ui::ensure_frame(&mut app);
+ press_esc(&mut app, &ctx);
+ assert_eq!(app.ui.view.screen_mode, "standard");
+}
+
#[test]
fn esc_leaves_full_screen_modes_unless_something_else_owns_it() {
let (mut app, ctx) = app_with(1);