mirror of
https://github.com/vale981/tridactyl
synced 2025-03-06 01:51:40 -05:00
Extract key translation from keyMap
This commit is contained in:
parent
8e9eff4ebe
commit
9246f28c1e
3 changed files with 13 additions and 6 deletions
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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") {
|
||||
|
|
Loading…
Add table
Reference in a new issue