mirror of
https://github.com/tridactyl/tridactyl.git
synced 2026-09-10 07:16:33 -04:00
Merge pull request #5249 from lawrencetheabhorrence/unbind-recursive
`:unbind --recursive`
This commit is contained in:
commit
bc6d051591
|
|
@ -4373,6 +4373,10 @@ export function comclear(name: string) {
|
|||
*/
|
||||
//#background
|
||||
export async function bind(...args: string[]) {
|
||||
if (args.includes("--recursive")) {
|
||||
throw new Error("`--recursive` can only be called on unbind.")
|
||||
}
|
||||
|
||||
const args_obj = parse_bind_args(...args)
|
||||
let p = Promise.resolve()
|
||||
if (args_obj.excmd !== "") {
|
||||
|
|
@ -4830,7 +4834,10 @@ export function blacklistadd(url: string) {
|
|||
return autocmd("DocStart", url, "mode ignore")
|
||||
}
|
||||
|
||||
/** Unbind a sequence of keys so that they do nothing at all.
|
||||
/**
|
||||
Unbind a sequence of keys so that they do nothing at all.
|
||||
|
||||
Accepts the flag `--recursive` to unbind all binds that start with the specified key sequence, e.g. `:unbind --recursive ;` unbinds all the binds like `;f` `;F` `;;` etc.
|
||||
|
||||
See also:
|
||||
|
||||
|
|
@ -4840,6 +4847,17 @@ export function blacklistadd(url: string) {
|
|||
//#background
|
||||
export async function unbind(...args: string[]) {
|
||||
const args_obj = parse_bind_args(...args)
|
||||
|
||||
if (args_obj.isRecursive) {
|
||||
const prefix = args_obj.key
|
||||
const maps = config.get(args_obj.configName as keyof config.default_config)
|
||||
for (const binding in maps) {
|
||||
if (binding.startsWith(prefix)) {
|
||||
config.set(args_obj.configName, binding, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args_obj.excmd !== "") throw new Error("unbind syntax: `unbind key`")
|
||||
if (args_obj.mode == "browser") {
|
||||
const commands = await browser.commands.getAll()
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ interface bind_args {
|
|||
configName: string
|
||||
key: string
|
||||
excmd: string
|
||||
isRecursive: boolean
|
||||
}
|
||||
|
||||
export function parse_bind_args(...args: string[]): bind_args {
|
||||
|
|
@ -35,9 +36,21 @@ export function parse_bind_args(...args: string[]): bind_args {
|
|||
const result = {} as bind_args
|
||||
result.mode = "normal"
|
||||
|
||||
if (args[0].startsWith("--mode=")) {
|
||||
result.mode = args.shift().replace("--mode=", "")
|
||||
const flags = []; // --mode and --recursive
|
||||
while (args[0].startsWith("--")) {
|
||||
flags.push(args.shift());
|
||||
}
|
||||
|
||||
for (const flag of flags) {
|
||||
if (flag.startsWith("--mode")) {
|
||||
result.mode = flag.replace("--mode=", "");
|
||||
} else if (flag == "--recursive") {
|
||||
result.isRecursive = true;
|
||||
} else {
|
||||
throw new Error("Invalid bind/unbind arguments.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!mode2maps.has(result.mode)) {
|
||||
result.configName = result.mode + "maps"
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue