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-candCtrl-Cmap to the same chord. - Letters without modifiers: case is preserved (vim’s
Ais uppercase a, distinct froma). - Letters with shift only: shift is folded into the
case (the terminal already uppercased the letter; we
strip the redundant
KeyMods::SHIFT).Shift-aandAcollapse. - 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 toSpecial(Tab) + KeyMods::SHIFTso the keymap trie has one entry rather than two for “shift-tab”.