From 5faf499d5c036661f4fe73018e2c05dd897559cc Mon Sep 17 00:00:00 2001 From: 00xJ0 <56056764+00xJ0@users.noreply.github.com> Date: Fri, 16 Oct 2026 20:11:17 -0700 Subject: [PATCH] Shortcuts: custom bindings on PageUp/PageDown (and other multi-word keys) fire again (#6827) normalize_shortcut title-cased every named key, so a binding set to Shift+PageUp was saved as Shift+Pageup, which egui's case-sensitive Key::from_name rejects: the shortcut never fired. Multi-word key names (PageUp, PageDown, Open/CloseBracket, Open/CloseCurlyBracket, BrowserBack, IntlBackslash) now keep egui's spelling, and shortcuts::parse matches key names case-insensitively so bindings saved by earlier versions work too. --- crates/engine/src/prefs.rs | 8 ++++++++ crates/engine/src/prefs/tests.rs | 5 +++++ crates/ui-egui/src/layer_shortcut_tests.rs | 20 ++++++++++++++++++++ crates/ui-egui/src/shortcuts.rs | 3 ++- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs index 77acd2e346..b33c06fead 100644 --- a/crates/engine/src/prefs.rs +++ b/crates/engine/src/prefs.rs @@ -1466,7 +1466,15 @@ pub fn normalize_shortcut(s: &str) -> Option { Some(s) } +/// Key names spelled with more than one capital (egui's `Key::name`): Title case would turn +/// `PageUp` into `Pageup`, which no key matches, so a binding saved that way never fired (#6827). +const MULTI_WORD_KEYS: [&str; 8] = + ["PageUp", "PageDown", "OpenBracket", "CloseBracket", "OpenCurlyBracket", "CloseCurlyBracket", "BrowserBack", "IntlBackslash"]; + fn capitalize(s: &str) -> String { + if let Some(k) = MULTI_WORD_KEYS.iter().find(|k| k.eq_ignore_ascii_case(s)) { + return (*k).to_string(); + } let mut c = s.chars(); match c.next() { Some(f) if f.is_ascii_alphabetic() => { diff --git a/crates/engine/src/prefs/tests.rs b/crates/engine/src/prefs/tests.rs index 55e41949b9..b0cb787d81 100644 --- a/crates/engine/src/prefs/tests.rs +++ b/crates/engine/src/prefs/tests.rs @@ -343,6 +343,11 @@ fn shortcuts_normalise_and_detect_conflicts() { assert_eq!(normalize_shortcut("Cmd++").as_deref(), Some("Cmd++")); assert_eq!(normalize_shortcut("Cmd+Shift"), None); assert_eq!(normalize_shortcut("Cmd+A+B"), None); + // #6827: multi-word key names keep egui's spelling (Title case made `Pageup`, matching no key). + assert_eq!(normalize_shortcut("shift+pageup").as_deref(), Some("Shift+PageUp")); + assert_eq!(normalize_shortcut("Ctrl+Alt+PAGEDOWN").as_deref(), Some("Ctrl+Alt+PageDown")); + assert_eq!(normalize_shortcut("Cmd+openbracket").as_deref(), Some("Cmd+OpenBracket")); + assert_eq!(normalize_shortcut("home").as_deref(), Some("Home")); let c = conflicts([("a", "Cmd+J"), ("b", "cmd+j"), ("c", "Cmd+K")]); assert_eq!(c, vec![("Cmd+J".to_string(), vec!["a".to_string(), "b".to_string()])]); } diff --git a/crates/ui-egui/src/layer_shortcut_tests.rs b/crates/ui-egui/src/layer_shortcut_tests.rs index 96ab2520dc..fc9dd93570 100644 --- a/crates/ui-egui/src/layer_shortcut_tests.rs +++ b/crates/ui-egui/src/layer_shortcut_tests.rs @@ -188,3 +188,23 @@ fn command_click_on_a_thumbnail_loads_transparency_except_on_the_background() { click(&mut h, shape, Modifiers::COMMAND); assert_eq!(bounds(&h), Some(photocraft_geom::Rect::new(100, 50, 220, 150)), "a hidden layer's transparency loads too"); } + +/// #6827: a custom binding on PageUp/PageDown fires (it was saved as `Pageup`, which matched no +/// key), and one saved that way by an earlier version still parses. +#[test] +fn custom_page_up_and_page_down_bindings_fire() { + for (binding, key, modifiers) in [ + ("Shift+PageUp", Key::PageUp, Modifiers::SHIFT), + ("Cmd+Shift+PageUp", Key::PageUp, Modifiers::COMMAND | Modifiers::SHIFT), + ("Cmd+Alt+PageDown", Key::PageDown, Modifiers::COMMAND | Modifiers::ALT), + ] { + let mut app = app(); + app.run("edit.fill", json!({"contents": "black"})).unwrap(); + app.run("edit.keyboardShortcuts", json!({"set": {"edit.transform.flipHorizontal": binding}, "removeConflicts": true})).unwrap(); + let before = app.session.journal.len(); + press(&mut app, key, modifiers); + let ran: Vec<&str> = app.session.journal[before..].iter().map(|(id, _)| id.as_str()).collect(); + assert_eq!(ran, ["edit.transform.flipHorizontal"], "{binding}"); + } + assert_eq!(crate::shortcuts::parse("Shift+Pageup"), Some(egui::KeyboardShortcut::new(Modifiers::SHIFT, Key::PageUp))); +} diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 1ad8d6d92a..81e64d7e0f 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -38,7 +38,8 @@ pub fn parse(s: &str) -> Option { ";" => Some(Key::Semicolon), "'" => Some(Key::Quote), "]" => Some(Key::CloseBracket), - name => Key::from_name(name), + // Case-insensitive too: bindings saved as `Shift+Pageup` before #6827 still work. + name => Key::from_name(name).or_else(|| Key::ALL.iter().find(|k| k.name().eq_ignore_ascii_case(name)).copied()), }?; Some(KeyboardShortcut::new(mods, key)) }