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

MapTarget

MapTarget: string | ((...args: any[]) => any)

Variables

Let KEYCODETRANSLATEMAP

KEYCODETRANSLATEMAP: {}

Type declaration

Let KEYMAP_CACHE

KEYMAP_CACHE: {}

Type declaration

Const bracketexpr_grammar

bracketexpr_grammar: Grammar = grammar

Const bracketexpr_parser

bracketexpr_parser: Parser = new Parser(bracketexpr_grammar)

Const mapstrModifiers

mapstrModifiers: Map<string, string> = new Map([...modifiers, ["D", "keydown"], ["U", "keyup"], ["?", "optional"]])

Const modifiers

modifiers: Map<string, string> = new Map([["A", "altKey"],["C", "ctrlKey"],["M", "metaKey"],["S", "shiftKey"],])

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[]

canonicaliseMapstr

  • canonicaliseMapstr(mapstr: string): string

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

findShadowingMapstr

  • findShadowingMapstr(mapstr: string, existingMapstrs: Iterable<string>): string | undefined
  • Return the first existing mapstr that would match before mapstr can complete.

    Parameters

    • mapstr: string
    • existingMapstrs: Iterable<string>

    Returns string | undefined

formatKeysForModeIndicator

  • formatKeysForModeIndicator(keys: MinimalKey[], mapstrs?: Iterable<string>): string

Const hasDirection

  • 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

    Returns boolean

hasModifiers

hasNonShiftModifiers

  • hasNonShiftModifiers(keyEvent: MinimalKey): boolean
  • shiftKey is true for any capital letter, most numbers, etc. Generally care about other modifiers.

    Parameters

    Returns boolean

Const isDigit

  • isDigit(d: string): boolean

Const isKeyup

isPerfectMatch

keyMap

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

    Parameters

    • conf: any

    Returns KeyMap

mapstrMapToKeyMap

mapstrToKeyseq

minimalKeyFromKeyboardEvent

  • minimalKeyFromKeyboardEvent(keyEvent: KeyboardEvent): MinimalKey
  • Convert keyboardEvent to internal type MinimalKey for further use. Key is obtained through layout-independent code if config says so.

    Parameters

    • keyEvent: KeyboardEvent

    Returns MinimalKey

minimalKeyToMozMap

mozMapToMinimalKey

numericPrefixToExstrSuffix

  • numericPrefixToExstrSuffix(numericPrefix: MinimalKey[]): string

parse

parseMapstr

  • parseMapstr(mapstr: string): { hasExplicitDirection: boolean; keyseq: MinimalKey[] }

prefixes

printableKey

  • printableKey(k: MinimalKey, showDirection: boolean): string

splitNumericPrefix

stripOnlyModifiers

  • stripOnlyModifiers(keyseq: any): any

updateBaseLayout

  • updateBaseLayout(): void

Object literals

Const commandKey2jsKey

commandKey2jsKey: object

Comma

Comma: string = ","

Down

Down: string = "ArrowDown"

Left

Left: string = "ArrowLeft"

Period

Period: string = "."

Right

Right: string = "ArrowRight"

Space

Space: string = " "

Up

Up: string = "ArrowUp"