Add user-definable modes

This commit is contained in:
Oliver Blanthorn 2019-05-30 15:37:06 +01:00
parent 2e4cdb9711
commit 30d3eb8f73
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
3 changed files with 12 additions and 4 deletions

View file

@ -138,7 +138,10 @@ function* ParserController() {
// unbounded length.
keyEvents.push(keyevent)
const response = parsers[contentState.mode](keyEvents)
const response = (
parsers[contentState.mode] ||
(keys => generic.parser(contentState.mode + "maps", keys))
)(keyEvents)
logger.debug(
currentMode,
contentState.mode,

View file

@ -2526,6 +2526,8 @@ export function version() {
* If you're looking for a way to temporarily disable Tridactyl, `mode ignore` might be what you're looking for.
*
* Note that when in ignore mode, Tridactyl will not switch to insert mode when focusing text areas/inputs. This is by design.
*
* **New feature:** you can add modes as simply as adding binds with `bind --mode=[newmodename]` and then enter the mode with `mode [newmodename]`.
*/
//#content
export function mode(mode: ModeName) {
@ -2972,9 +2974,11 @@ function parse_bind_args(...args: string[]): bind_args {
if (args[0].startsWith("--mode=")) {
result.mode = args.shift().replace("--mode=", "")
}
if (!mode2maps.has(result.mode)) throw new Error("Mode " + result.mode + " does not yet have user-configurable binds.")
result.configName = mode2maps.get(result.mode)
if (!mode2maps.has(result.mode)) {
result.configName = result.mode + "maps"
} else {
result.configName = mode2maps.get(result.mode)
}
const key = args.shift()
// Convert key to internal representation

View file

@ -5,6 +5,7 @@ import * as keyseq from "@src/lib/keyseq"
export function parser(conf, keys): keyseq.ParserResponse {
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")
// If so configured, translate keys using the key translation map
if (config.get("keytranslatemodes")[conf] === "true") {