Merge PR #6912: Shortcuts: custom bindings on PageUp/PageDown (and other multi-word keys) fire again (#6827)

This commit is contained in:
aiongg committed 2026-10-21 21:55:49 +00:00
commit 5ef5c71164
4 files changed
+35 -1

No files matched your search

+8
View File
@@ -1491,7 +1491,15 @@ pub fn normalize_shortcut(s: &str) -> Option<String> {
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() => {
+5
View File
@@ -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()])]);
}
@@ -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)));
}
+2 -1
View File
@@ -38,7 +38,8 @@ pub fn parse(s: &str) -> Option<KeyboardShortcut> {
";" => 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))
}