From 30d3eb8f736aeba61128e0b8116cabc65fd11f20 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Thu, 30 May 2019 15:37:06 +0100 Subject: [PATCH] Add user-definable modes --- src/content/controller_content.ts | 5 ++++- src/excmds.ts | 10 +++++++--- src/parsers/genericmode.ts | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/content/controller_content.ts b/src/content/controller_content.ts index fc305733..82c56ea8 100644 --- a/src/content/controller_content.ts +++ b/src/content/controller_content.ts @@ -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, diff --git a/src/excmds.ts b/src/excmds.ts index 25b9e018..62193821 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -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 diff --git a/src/parsers/genericmode.ts b/src/parsers/genericmode.ts index 379d0ede..883de917 100644 --- a/src/parsers/genericmode.ts +++ b/src/parsers/genericmode.ts @@ -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 and add binds, e.g. :bind --mode=[mode] mode normal") // If so configured, translate keys using the key translation map if (config.get("keytranslatemodes")[conf] === "true") {