diff options
author | 2024-05-31 16:10:59 +0200 | |
---|---|---|
committer | 2024-05-31 16:14:55 +0200 | |
commit | 8cfa8149f56a0e58eb0257ebb181c69bec5c095f (patch) | |
tree | 0671f634db187f967426e6264d535dd60c0af9b7 /widget/src | |
parent | bd48946b02268cb5a7ae932e388abfa75fe9e375 (diff) | |
download | iced-8cfa8149f56a0e58eb0257ebb181c69bec5c095f.tar.gz iced-8cfa8149f56a0e58eb0257ebb181c69bec5c095f.tar.bz2 iced-8cfa8149f56a0e58eb0257ebb181c69bec5c095f.zip |
Keep unary `motion` function in `text_editor`
Diffstat (limited to 'widget/src')
-rw-r--r-- | widget/src/text_editor.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 3b6647e4..9e494394 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -767,7 +767,19 @@ impl Update { } if let keyboard::Key::Named(named_key) = key.as_ref() { - if let Some(motion) = motion(named_key, modifiers) { + if let Some(motion) = motion(named_key) { + let motion = if platform::is_macos_command_pressed( + modifiers, + ) { + match motion { + Motion::Left => Motion::Home, + Motion::Right => Motion::End, + _ => motion, + } + } else { + motion + }; + let motion = if platform::is_jump_modifier_pressed( modifiers, ) { @@ -793,26 +805,14 @@ impl Update { } } -fn motion(key: key::Named, modifiers: keyboard::Modifiers) -> Option<Motion> { +fn motion(key: key::Named) -> Option<Motion> { match key { - key::Named::Home => Some(Motion::Home), - key::Named::End => Some(Motion::End), - key::Named::ArrowLeft => { - if platform::is_macos_command_pressed(modifiers) { - Some(Motion::Home) - } else { - Some(Motion::Left) - } - } - key::Named::ArrowRight => { - if platform::is_macos_command_pressed(modifiers) { - Some(Motion::End) - } else { - Some(Motion::Right) - } - } + key::Named::ArrowLeft => Some(Motion::Left), + key::Named::ArrowRight => Some(Motion::Right), key::Named::ArrowUp => Some(Motion::Up), key::Named::ArrowDown => Some(Motion::Down), + key::Named::Home => Some(Motion::Home), + key::Named::End => Some(Motion::End), key::Named::PageUp => Some(Motion::PageUp), key::Named::PageDown => Some(Motion::PageDown), _ => None, |