diff options
author | Gokul Soumya | 2021-07-26 16:07:13 +0000 |
---|---|---|
committer | GitHub | 2021-07-26 16:07:13 +0000 |
commit | 88d6f652390922b389667f469b6d308db569bdaf (patch) | |
tree | 12d23bd03d89744880e87fca12f192e676272ee9 /helix-view/src/input.rs | |
parent | a630fb5d2022b264bcac34317bbadd0973bd57d4 (diff) |
Allow multi key remappings in config file (#454)
* Use tree like structure to store keymaps
* Allow multi key keymaps in config file
* Allow multi key keymaps in insert mode
* Make keymap state self contained
* Add keymap! macro for ergonomic declaration
* Add descriptions for editor commands
* Allow keymap! to take multiple keys
* Restore infobox display
* Fix keymap merging and add infobox titles
* Fix and add tests for keymaps
* Clean up comments and apply suggestions
* Allow trailing commas in keymap!
* Remove mode suffixes from keymaps
* Preserve order of keys when showing infobox
* Make command descriptions smaller
* Strip infobox title prefix from items
* Strip infobox title prefix from items
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)?; |