diff options
author | Nathan Vegdahl | 2021-07-26 18:19:10 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-26 18:19:10 +0000 |
commit | f62ec6e51e99dce9e93600801c3637c196c592b6 (patch) | |
tree | 8821ee23ade21c0da4fbb5a70143717ac42a2bc1 /helix-view/src/input.rs | |
parent | 5ee6ba5b38ebeb86006bb2e42734a2285eb354df (diff) | |
parent | 88d6f652390922b389667f469b6d308db569bdaf (diff) |
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
Diffstat (limited to 'helix-view/src/input.rs')
-rw-r--r-- | helix-view/src/input.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 2847bb69..8d9ee6fb 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -14,6 +14,16 @@ pub struct KeyEvent { pub modifiers: KeyModifiers, } +impl KeyEvent { + /// Get only the character involved in this event + pub fn char(&self) -> Option<char> { + match self.code { + KeyCode::Char(ch) => Some(ch), + _ => None, + } + } +} + pub(crate) mod keys { pub(crate) const BACKSPACE: &str = "backspace"; pub(crate) const ENTER: &str = "ret"; @@ -168,7 +178,7 @@ impl std::str::FromStr for KeyEvent { keys::MINUS => KeyCode::Char('-'), keys::SEMICOLON => KeyCode::Char(';'), keys::PERCENT => KeyCode::Char('%'), - single if single.len() == 1 => KeyCode::Char(single.chars().next().unwrap()), + single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()), function if function.len() > 1 && function.starts_with('F') => { let function: String = function.chars().skip(1).collect(); let function = str::parse::<u8>(&function)?; |