diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs index 419468426a..222bf53685 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine/src/prefs.rs @@ -1519,7 +1519,8 @@ pub const TEMPORARY_TOOLS: &[(&str, &str, &str)] = &[ /// Photoshop's second default keys (#3665): (command, key). Each command keeps its main key /// (the one its menu shows) and answers these as well, as in Photoshop's default set: the /// legacy function keys F2 Cut, F3 Copy, F4 Paste and Shift+F7 Inverse; Shift+Backspace -/// (Shift+Delete on a Mac) for Fill; and ⌘+ beside ⌘= for Zoom In. +/// (Shift+Delete on a Mac) for Fill; ⌘+ beside ⌘= for Zoom In; and off the Mac, Ctrl+F4 beside +/// Ctrl+W for Close (Windows' close-document key; macOS keeps Ctrl+F4 for window focus). pub const ALTERNATE_SHORTCUTS: &[(&str, &str)] = &[ ("edit.cut", "F2"), ("edit.copy", "F3"), @@ -1527,6 +1528,8 @@ pub const ALTERNATE_SHORTCUTS: &[(&str, &str)] = &[ ("edit.fill", "Shift+Backspace"), ("select.inverse", "Shift+F7"), ("view.zoomIn", "Cmd++"), + #[cfg(not(target_os = "macos"))] + ("file.close", "Cmd+F4"), ]; /// A command's default alternate keys ([`ALTERNATE_SHORTCUTS`]). diff --git a/crates/ui-egui/src/shortcut_dispatch/tests.rs b/crates/ui-egui/src/shortcut_dispatch/tests.rs index 00f1a120a3..2c1fee6900 100644 --- a/crates/ui-egui/src/shortcut_dispatch/tests.rs +++ b/crates/ui-egui/src/shortcut_dispatch/tests.rs @@ -356,6 +356,24 @@ fn alternate_keys_run_their_command() { assert!(take_log(&h.ctx).is_empty()); } +/// Ctrl+F4 closes the document beside Ctrl+W, as in Photoshop on Windows, through the same +/// guarded Close: unsaved changes still get the save prompt. +#[cfg(not(target_os = "macos"))] +#[test] +fn ctrl_f4_closes_the_document() { + let mut h = harness(); + put_focus(&mut h, Place::Canvas); + press(&mut h, "Cmd+F4"); + assert!(matches!(take_log(&h.ctx).as_slice(), [(id, Outcome::Ran)] if id == "file.close")); + assert!(h.state().discard.is_some(), "unsaved changes ask first"); + assert_eq!(h.state().session.documents().len(), 1); + h.state_mut().discard = None; + let st = h.state_mut().session.active_mut().unwrap(); + st.saved_revision = st.revision; + press(&mut h, "Cmd+F4"); + assert!(h.state().session.documents().is_empty(), "a saved document closes"); +} + /// #352: ⌥[ ⌥] ⌥, ⌥. and ⇧⌥[ walk the Layers panel's rows from the keyboard. #[test] fn alt_brackets_walk_the_layers_panel() {