From 68abc67ec6846ab4d05b0e46d1baa65dc026e7dd Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Thu, 3 Jun 2021 12:14:02 +0200 Subject: put the key canonicalization in a seperate function. only chars now get stripped of Shift modifier --- helix-term/src/ui/editor.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 19db3fa7..0b0ad5ed 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -547,11 +547,6 @@ impl Component for EditorView { // clear status cx.editor.status_msg = None; - //canonicalize the key - if key.modifiers == KeyModifiers::SHIFT { - key.modifiers = KeyModifiers::NONE; - } - let (view, doc) = cx.editor.current(); let mode = doc.mode(); @@ -570,7 +565,7 @@ impl Component for EditorView { match mode { Mode::Insert => { // record last_insert key - self.last_insert.1.push(key); + self.last_insert.1.push(canonicalize_key(&mut key)); // let completion swallow the event if necessary let mut consumed = false; @@ -595,7 +590,7 @@ impl Component for EditorView { // if completion didn't take the event, we pass it onto commands if !consumed { - self.insert_mode(&mut cxt, key); + self.insert_mode(&mut cxt, canonicalize_key(&mut key)); // lastly we recalculate completion if let Some(completion) = &mut self.completion { @@ -606,7 +601,7 @@ impl Component for EditorView { } } } - mode => self.command_mode(mode, &mut cxt, key), + mode => self.command_mode(mode, &mut cxt, canonicalize_key(&mut key)), } } @@ -695,3 +690,10 @@ impl Component for EditorView { None } } + +fn canonicalize_key(key: &mut KeyEvent) -> KeyEvent { + if let KeyEvent { code: KeyCode::Char(_), modifiers: KeyModifiers::SHIFT } = key { + key.modifiers = KeyModifiers::NONE; + } + *key +} \ No newline at end of file -- cgit v1.2.3-70-g09d2