Extract key translation from keyMap

This commit is contained in:
Oliver Blanthorn 2020-05-31 15:17:01 +01:00
parent 8e9eff4ebe
commit 9246f28c1e
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
3 changed files with 13 additions and 6 deletions

View file

@ -350,15 +350,20 @@ export function mapstrMapToKeyMap(mapstrMap: Map<string, MapTarget>): KeyMap {
return newKeyMap
}
export function keyMap(conf, keys): KeyMap {
let maps: any = config.get(conf)
if (maps === undefined) throw new Error("No binds defined for this mode. Reload page with <C-r> and add binds, e.g. :bind --mode=[mode] <Esc> mode normal")
export function translateKeysInPlace(keys, conf): void {
// If so configured, translate keys using the key translation map
if (config.get("keytranslatemodes")[conf] === "true") {
const translationmap = config.get("keytranslatemap")
translateKeysUsingKeyTranslateMap(keys, translationmap)
}
}
/**
* Return a "*maps" config converted into sequences of minimalkeys (e.g. "nmaps")
*/
export function keyMap(conf): KeyMap {
let maps: any = config.get(conf)
if (maps === undefined) throw new Error("No binds defined for this mode. Reload page with <C-r> and add binds, e.g. :bind --mode=[mode] <Esc> mode normal")
// Convert to KeyMap
maps = new Map(Object.entries(maps))

View file

@ -3,6 +3,7 @@
import * as keyseq from "@src/lib/keyseq"
export function parser(conf, keys): keyseq.ParserResponse {
const maps = keyseq.keyMap(conf, keys)
const maps = keyseq.keyMap(conf)
keyseq.translateKeysInPlace(keys, conf)
return keyseq.parse(keys, maps)
}

View file

@ -29,7 +29,8 @@ export function parser(keys: KeyboardEvent[]) {
keys = keyseq.stripOnlyModifiers(keys)
if (keys.length === 0) return { keys: [], isMatch: false }
const conf = mode2maps.get(modeState.mode) || modeState.mode + "maps"
const maps: any = keyseq.keyMap(conf, keys)
const maps: any = keyseq.keyMap(conf)
keyseq.translateKeysInPlace(keys, conf)
const key = keys[0].key
if (key === "Escape") {