Key-sequence parser

If map is a Map of MinimalKey[] to objects (exstrs or callbacks) and keyseq is an array of MinimalKey compatible objects...

  • parse(keyseq, map) returns the mapped object and a count OR a prefix of MinimalKey[] (possibly empty) that, if more keys are pressed, could map to an object.
  • completions(keyseq, map) returns the fragment of map that keyseq is a valid prefix of.
  • mapstrToKeySeq generates KeySequences for the rest of the API.

No key sequence in a map may be a prefix of another key sequence in that map. This is a point of difference from Vim that removes any time-dependence in the parser. Vimperator, Pentadactyl, saka-key, etc, all share this limitation.

If a key is represented by a single character then the shift modifier state is ignored unless other modifiers are also present.

MinimalKey
KeyModifiers
ParserResponse
KeyEventLike
TrustedKeyboardEvent
commandKey2jsKey
guarded
bracketexprToKey
canonicaliseMapstr
completions
findShadowingMapstr
formatKeysForModeIndicator
hasModifiers
hasNonShiftModifiers
isTrustedKeyboardEvent
keyMap
mapstrMapToKeyMap
mapstrMatchesKey
mapstrToKeyseq
minimalKeyFromKeyboardEvent
minimalKeyToMozMap
mozMapToMinimalKey
parse
parseMapstr
stripOnlyModifiers
TrustedKeyboardEvent: KeyboardEvent & { isTrusted: true }
commandKey2jsKey: object = ...
Comma: string = ","
Down: string = "ArrowDown"
Left: string = "ArrowLeft"
Period: string = "."
Right: string = "ArrowRight"
Space: string = " "
Up: string = "ArrowUp"
guarded: (
    arg: (keyevent: TrustedKeyboardEvent) => unknown,
) => (keyevent: Event) => unknown = ...

Type Declaration

  • String starting with a < to MinimalKey and remainder.

    Bracket expressions generally start with a < contain no angle brackets or whitespace and end with a >. These special-cased expressions are also permitted: <{modifier}<>, <{modifier}>>, and <{modifier}->.

    If the string passed does not match this definition, it is treated as a literal <.

    Backus Naur approximation:

        - bracketexpr ::= '<' modifier? key '>'
    - modifier ::= 'm'|'s'|'a'|'c' '-'
    - key ::= '<'|'>'|/[^\s<>-]+/

    See src/grammars/bracketExpr.ne for the canonical definition.

    Modifiers are case insensitive.

    Some case insensitive vim compatibility aliases are also defined, see expandAliases.

    Compatibility breaks:

    Shift + key must use the correct capitalisation of key: <S-j> != J, <S-J> == J.

    In Vim <A-x> == <M-x> on most systems. Not so here: we can't detect platform, so just have to use what the browser gives us.

    Vim has a predefined list of special key sequences, we don't: there are too many (and they're non-standard) 1.

    In the future, we may just use the names as defined in keyNameList.h 2.

    In Vim, you're still allowed to use <lt> within angled brackets: <M-<> == <M-lt> == <M-<lt>> Here only the first two will work.

    Restrictions:

    It is not possible to map to a keyevent that actually sends the key value of any of the aliases or to any multi-character sequence containing a space or >. It is unlikely that browsers will ever do either of those things.

    Parameters

    • inputStr: any

    Returns any[]

  • Parameters

    • mapstr: string

    Returns string

  • returns the fragment of map that keyseq is a valid prefix of.

    Parameters

    Returns KeyMap

  • Return the first existing mapstr that would match before mapstr can complete.

    Parameters

    • mapstr: string
    • existingMapstrs: Iterable<string>

    Returns string

  • Parameters

    • keys: MinimalKey[]
    • mapstrs: Iterable<string> = []

    Returns string

  • shiftKey is true for any capital letter, most numbers, etc. Generally care about other modifiers.

    Parameters

    Returns boolean

  • Return a "*maps" config converted into sequences of minimalkeys (e.g. "nmaps")

    Parameters

    • conf: any

    Returns KeyMap

  • Convert a map of mapstrs (e.g. from config) to a KeyMap

    Parameters

    • mapstrMap: Map<string, MapTarget>

    Returns KeyMap

  • Parameters

    • mapstr: string

    Returns { hasExplicitDirection: boolean; keyseq: MinimalKey[] }

  • Parameters

    • keyseq: any

    Returns any