diff options
| author | 2024-05-31 16:23:09 +0200 | |
|---|---|---|
| committer | 2024-05-31 16:23:09 +0200 | |
| commit | 3312dc808012e2c049fb2f178d51bfe0b4e30399 (patch) | |
| tree | 5dbfe97e50662cdaf396427d7793c4f03fc159c6 /core/src/keyboard | |
| parent | 8cfa8149f56a0e58eb0257ebb181c69bec5c095f (diff) | |
| download | iced-3312dc808012e2c049fb2f178d51bfe0b4e30399.tar.gz iced-3312dc808012e2c049fb2f178d51bfe0b4e30399.tar.bz2 iced-3312dc808012e2c049fb2f178d51bfe0b4e30399.zip  | |
Create `jump` and `macos_command` methods in `keyboard::Modifiers`
Diffstat (limited to 'core/src/keyboard')
| -rw-r--r-- | core/src/keyboard/modifiers.rs | 24 | 
1 files changed, 24 insertions, 0 deletions
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 +        } +    }  }  | 
