diff options
author | 2024-05-31 16:23:09 +0200 | |
---|---|---|
committer | 2024-05-31 16:23:09 +0200 | |
commit | 3312dc808012e2c049fb2f178d51bfe0b4e30399 (patch) | |
tree | 5dbfe97e50662cdaf396427d7793c4f03fc159c6 /widget/src/text_editor.rs | |
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 'widget/src/text_editor.rs')
-rw-r--r-- | widget/src/text_editor.rs | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 9e494394..41b058af 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -768,9 +768,7 @@ impl Update { if let keyboard::Key::Named(named_key) = key.as_ref() { if let Some(motion) = motion(named_key) { - let motion = if platform::is_macos_command_pressed( - modifiers, - ) { + let motion = if modifiers.macos_command() { match motion { Motion::Left => Motion::Home, Motion::Right => Motion::End, @@ -780,9 +778,7 @@ impl Update { motion }; - let motion = if platform::is_jump_modifier_pressed( - modifiers, - ) { + let motion = if modifiers.jump() { motion.widen() } else { motion @@ -819,31 +815,6 @@ fn motion(key: key::Named) -> Option<Motion> { } } -mod platform { - use crate::core::keyboard; - - pub fn is_jump_modifier_pressed(modifiers: keyboard::Modifiers) -> bool { - if cfg!(target_os = "macos") { - modifiers.alt() - } else { - modifiers.control() - } - } - - /// Whether the command key is pressed on a macOS device. - /// - /// This is relevant for actions like ⌘ + ArrowLeft to move to the beginning of the - /// line where the equivalent behavior for `modifiers.command()` is instead a jump on - /// other platforms. - pub fn is_macos_command_pressed(modifiers: keyboard::Modifiers) -> bool { - if cfg!(target_os = "macos") { - modifiers.logo() - } else { - false - } - } -} - /// The possible status of a [`TextEditor`]. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Status { |