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.
returns the fragment of map
that keyseq is a valid prefix of.
Expand special key aliases that Vim provides to canonical values
Vim aliases are case insensitive.
shiftKey is true for any capital letter, most numbers, etc. Generally care about other modifiers.
A simple key event is a non-special key (length 1) that is not modified by ctrl, alt, or shift.
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)
True if seq1 is a prefix or equal to seq2
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.
Key-sequence parser
If
map
is a Map ofMinimalKey[]
to objects (exstrs or callbacks) andkeyseq
is an array of MinimalKey compatible objects...parse(keyseq, map)
returns the mapped object and a count OR a prefix ofMinimalKey[]
(possibly empty) that, if more keys are pressed, could map to an object.completions(keyseq, map)
returns the fragment ofmap
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.