From 3312dc808012e2c049fb2f178d51bfe0b4e30399 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 31 May 2024 16:23:09 +0200 Subject: Create `jump` and `macos_command` methods in `keyboard::Modifiers` --- core/src/keyboard/modifiers.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'core/src/keyboard') diff --git a/core/src/keyboard/modifiers.rs b/core/src/keyboard/modifiers.rs index e531510f..edbf6d38 100644 --- a/core/src/keyboard/modifiers.rs +++ b/core/src/keyboard/modifiers.rs @@ -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 + } + } } -- cgit