This logic can mostly be replaced with `CodeMirror.keyName`