From 88d6f652390922b389667f469b6d308db569bdaf Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Mon, 26 Jul 2021 21:37:13 +0530 Subject: 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--- helix-view/src/input.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'helix-view/src/input.rs') 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 { + 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::(&function)?; -- cgit v1.2.3-70-g09d2