Skip to main content

from_event

Function from_event 

Source
pub fn from_event(event: &KeyEvent) -> Option<KeyChord>
Expand description

Normalise a crossterm::KeyEvent into a canonical KeyChord. Returns None for events that have no chord representation (release events on terminals that emit them, modifier-only presses, key codes we don’t recognise).

Normalisation rules (canonical form that the keymap trie indexes by):

  • Letters with Ctrl / Alt: case is folded to lowercase so Ctrl-c and Ctrl-C map to the same chord.
  • Letters without modifiers: case is preserved (vim’s A is uppercase a, distinct from a).
  • Letters with shift only: shift is folded into the case (the terminal already uppercased the letter; we strip the redundant KeyMods::SHIFT). Shift-a and A collapse.
  • Non-letter chars: shift is stripped (the terminal reports the shifted symbol, e.g. $ for shift-4; the modifier would be redundant).
  • Specials with shift: shift is preserved (<S-Tab> is distinct from <Tab>).
  • KeyCode::BackTab: canonicalised to Special(Tab) + KeyMods::SHIFT so the keymap trie has one entry rather than two for “shift-tab”.