Skip to content

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

fix(shortcuts): plain , and ; bindings follow the typed character on AZERTY (#7521)

Alexis449b99a74e6c
diff --git a/contributors/people.toml b/contributors/people.toml
index 3948e2992..102c69e66 100644
--- a/contributors/people.toml
+++ b/contributors/people.toml
@@ -169,3 +169,6 @@ sync_github_name = true
[people.Silvertree2010]
display_name = "Netter"
sync_github_name = false
+
+[people.Byxis]
+sync_github_name = true
diff --git a/crates/ui-egui/src/shortcut_dispatch.rs b/crates/ui-egui/src/shortcut_dispatch.rs
index 4336315db..ffc1a7f6e 100644
--- a/crates/ui-egui/src/shortcut_dispatch.rs
+++ b/crates/ui-egui/src/shortcut_dispatch.rs
@@ -215,7 +215,9 @@ fn key_owner(app: &PhotocraftApp, ctx: &egui::Context) -> (bool, usize, bool, bo
}
/// Keys whose shortcuts follow the key's position, as in Photoshop: ⇧⌘. is ⇧⌘> on a US layout,
-/// but types `:` on Nordic and German ones, so its character would never match.
+/// but types `:` on Nordic and German ones, so its character would never match. Only ⌘ shortcuts
+/// follow the position: a plain `,` or `;` binding (brush hardness on AZERTY, where `;` sits on the
+/// US comma key) must match the character typed.
const POSITIONAL: [Key; 2] = [Key::Period, Key::Comma];
/// Dispatch this frame's shortcut presses in the order they arrived (⌘Z then ⌘S undoes, then
@@ -236,7 +238,7 @@ pub fn dispatch_pressed(app: &mut PhotocraftApp, ctx: &egui::Context, focus: Foc
egui::Event::Key { key, physical_key, pressed: true, modifiers, .. } => {
let by_position = physical_key
.filter(|p| POSITIONAL.contains(p))
- .and_then(|p| table.iter().find(|(_, sc)| sc.logical_key == p && key_matches(sc, p, *modifiers)));
+ .and_then(|p| table.iter().find(|(_, sc)| sc.modifiers.command && sc.logical_key == p && key_matches(sc, p, *modifiers)));
by_position.or_else(|| table.iter().find(|(_, sc)| key_matches(sc, *key, *modifiers))).map(|(id, _)| (id.clone(), *key == Key::Tab))
}
_ => None,
diff --git a/crates/ui-egui/src/shortcut_dispatch/tests.rs b/crates/ui-egui/src/shortcut_dispatch/tests.rs
index 2827671a8..00f1a120a 100644
--- a/crates/ui-egui/src/shortcut_dispatch/tests.rs
+++ b/crates/ui-egui/src/shortcut_dispatch/tests.rs
@@ -804,3 +804,23 @@ fn type_size_keys_follow_key_position_and_the_typed_selection() {
assert_eq!(logged(&h), ["type.decreaseSize"]);
assert_eq!(sizes(&h), [(2, base), (3, base + 2.0)], "only the selected \"He\" shrinks");
}
+
+/// AZERTY: `;` sits on the US comma key and `,` on the US M key. Plain `,` / `;` bindings (brush
+/// hardness) must match the character typed, not the key's position, or `;` fires `,`'s command.
+#[test]
+fn plain_comma_and_semicolon_bindings_follow_the_typed_character_on_azerty() {
+ let mut h = harness();
+ h.state_mut().session.edit_prefs(|p| {
+ p.shortcuts.insert("tools.decreaseBrushHardness".into(), ",".into());
+ p.shortcuts.insert("tools.increaseBrushHardness".into(), ";".into());
+ });
+ let tap = |h: &mut Harness<'_, PhotocraftApp>, key, physical| {
+ h.event(egui::Event::Key { key, physical_key: Some(physical), pressed: true, repeat: false, modifiers: Modifiers::NONE });
+ h.event(egui::Event::Key { key, physical_key: Some(physical), pressed: false, repeat: false, modifiers: Modifiers::NONE });
+ h.run_steps(2);
+ };
+ tap(&mut h, egui::Key::Semicolon, egui::Key::Comma);
+ assert_eq!(logged(&h), ["tools.increaseBrushHardness"]);
+ tap(&mut h, egui::Key::Comma, egui::Key::M);
+ assert_eq!(logged(&h), ["tools.decreaseBrushHardness"]);
+}