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.

Index

Type aliases

KeyEventLike

KeyEventLike: MinimalKey | KeyboardEvent

KeyMap

KeyMap: Map<MinimalKey[], MapTarget>

MapTarget

MapTarget: string | function

Variables

Const bracketexpr_parser

bracketexpr_parser: Parser = new Parser(bracketexpr_grammar)

Functions

bracketexprToKey

  • bracketexprToKey(inputStr: any): any[]
  • 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[]

completions

expandAliases

  • expandAliases(key: string): any
  • Expand special key aliases that Vim provides to canonical values

    Vim aliases are case insensitive.

    Parameters

    • key: string

    Returns any

hasModifiers

hasNonShiftModifiers

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

    Parameters

    Returns boolean

isSimpleKey

  • A simple key event is a non-special key (length 1) that is not modified by ctrl, alt, or shift.

    Parameters

    Returns boolean

mapstrMapToKeyMap

mapstrToKeyseq

  • Generate KeySequences for the rest of the API.

    A map expression is something like:

    j scrollline 10
    <C-f> scrollpage 0.5
    <C-d> scrollpage 0.5
    <C-/><C-n> mode normal

    A mapstr is the bit before the space.

    mapstrToKeyseq turns a mapstr into a keySequence that looks like this:

    [MinimalKey {key: 'j'}]
    [MinimalKey {key: 'f', ctrlKey: true}]
    [MinimalKey {key: 'd', ctrlKey: true}]
    [MinimalKey {key: '/', ctrlKey: true}, MinimalKey {key: 'n', ctrlKey: true}]

    (All four {modifier}Key flags are actually provided on all MinimalKeys)

    Parameters

    • mapstr: string

    Returns MinimalKey[]

numericPrefixToExstrSuffix

  • numericPrefixToExstrSuffix(numericPrefix: KeyEventLike[]): string

parse

prefixes

splitNumericPrefix

translateKeysUsingKeyTranslateMap

  • translateKeysUsingKeyTranslateMap(keyEvents: KeyEventLike[], keytranslatemap: object): void
  • Translates the given set of keyEvents (in place) as specified by the given key translation map. All keys and values in the key translation map must be length-1 strings.

    Parameters

    • keyEvents: KeyEventLike[]
    • keytranslatemap: object
      • [inkey: string]: string

    Returns void