freya_core/events/modifiers.rs
1use keyboard_types::Modifiers;
2
3use crate::platform::TargetPlatform;
4
5/// Extension trait for [`Modifiers`] adding platform-aware helpers.
6pub trait ModifiersExt {
7 /// Returns the platform's command modifier.
8 ///
9 /// Maps to [`Modifiers::META`] (Command) on macOS and to [`Modifiers::CONTROL`]
10 /// on every other platform. Useful to express shortcuts like copy, paste or
11 /// select-all once and have them work natively on every OS.
12 fn ctrl_or_meta() -> Modifiers;
13
14 /// Returns the platform's word navigation modifier.
15 ///
16 /// Maps to [`Modifiers::ALT`] (Option) on macOS and to [`Modifiers::CONTROL`]
17 /// on every other platform. Used for word-wise cursor movement and deletion.
18 fn ctrl_or_alt() -> Modifiers;
19}
20
21impl ModifiersExt for Modifiers {
22 fn ctrl_or_meta() -> Modifiers {
23 match TargetPlatform::get() {
24 TargetPlatform::MacOs => Modifiers::META,
25 _ => Modifiers::CONTROL,
26 }
27 }
28
29 fn ctrl_or_alt() -> Modifiers {
30 match TargetPlatform::get() {
31 TargetPlatform::MacOs => Modifiers::ALT,
32 _ => Modifiers::CONTROL,
33 }
34 }
35}