Skip to content

Commit

Permalink
put the key canonicalization in a seperate function. only chars now g…
Browse files Browse the repository at this point in the history
…et stripped of Shift modifier
  • Loading branch information
janhrastnik authored and archseer committed Jun 3, 2021
1 parent 712f25c commit 68abc67
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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)),
}
}

Expand Down Expand Up @@ -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
}

0 comments on commit 68abc67

Please sign in to comment.