diff options
Diffstat (limited to 'usr.bin/tmux/key-bindings.c')
-rw-r--r-- | usr.bin/tmux/key-bindings.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c index 29a37c679a4..5ad2c778858 100644 --- a/usr.bin/tmux/key-bindings.c +++ b/usr.bin/tmux/key-bindings.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key-bindings.c,v 1.129 2020/06/03 16:35:40 nicm Exp $ */ +/* $OpenBSD: key-bindings.c,v 1.130 2020/06/16 08:18:34 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -232,6 +232,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) { struct key_table *table; @@ -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) { |