Create jump and macos_command methods in keyboard::Modifiers

This commit is contained in:
Héctor Ramón Jiménez 2024-05-31 16:23:09 +02:00
parent 8cfa8149f5
commit 3312dc8080
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 32 additions and 70 deletions

View file

@ -84,4 +84,28 @@ impl Modifiers {
is_pressed
}
/// Returns true if the "jump key" is pressed in the [`Modifiers`].
///
/// The "jump key" is the modifier key used to widen text motions. It is the `Alt`
/// key in macOS and the `Ctrl` key in other platforms.
pub fn jump(self) -> bool {
if cfg!(target_os = "macos") {
self.alt()
} else {
self.control()
}
}
/// Returns true if the "command key" is pressed on a macOS device.
///
/// This is relevant for macOS-specific actions (e.g. `⌘ + ArrowLeft` moves the cursor
/// to the beginning of the line).
pub fn macos_command(self) -> bool {
if cfg!(target_os = "macos") {
self.logo()
} else {
false
}
}
}