d and D keys to reset to default in customize mode.

This commit is contained in:
nicm
2020-06-16 08:18:34 +00:00
parent afe4ea4250
commit 1bf9555e4f
8 changed files with 222 additions and 54 deletions

View File

@ -231,6 +231,38 @@ key_bindings_remove(const char *name, key_code key)
}
}
void
key_bindings_reset(const char *name, key_code key)
{
struct key_table *table;
struct key_binding *bd, *dd;
table = key_bindings_get_table(name, 0);
if (table == NULL)
return;
bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS);
if (bd == NULL)
return;
dd = key_bindings_get_default(table, bd->key);
if (dd == NULL) {
key_bindings_remove(name, bd->key);
return;
}
cmd_list_free(bd->cmdlist);
bd->cmdlist = dd->cmdlist;
bd->cmdlist->references++;
free((void *)bd->note);
if (dd->note != NULL)
bd->note = xstrdup(dd->note);
else
bd->note = NULL;
bd->flags = dd->flags;
}
void
key_bindings_remove_table(const char *name)
{
@ -248,6 +280,23 @@ key_bindings_remove_table(const char *name)
}
}
void
key_bindings_reset_table(const char *name)
{
struct key_table *table;
struct key_binding *bd, *bd1;
table = key_bindings_get_table(name, 0);
if (table == NULL)
return;
if (RB_EMPTY(&table->default_key_bindings)) {
key_bindings_remove_table(name);
return;
}
RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1)
key_bindings_reset(name, bd->key);
}
static enum cmd_retval
key_bindings_init_done(__unused struct cmdq_item *item, __unused void *data)
{