diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2018-11-26 21:27:29 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2018-11-26 21:27:29 +0000 |
commit | 2fa568c628f5a66c5ca2cb8ef79528a1b4287080 (patch) | |
tree | 7d430f8ba2d0f24464c0a42052224f12526ea6ac | |
parent | d2b8d20d43b01a37737c39e35effbf334a21617d (diff) | |
download | imv-2fa568c628f5a66c5ca2cb8ef79528a1b4287080.tar.gz |
binds: Add imv_binds_clear_key
-rw-r--r-- | src/binds.c | 24 | ||||
-rw-r--r-- | src/binds.h | 3 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/binds.c b/src/binds.c index 9e268b4..3408ad9 100644 --- a/src/binds.c +++ b/src/binds.c @@ -130,6 +130,30 @@ void imv_binds_clear(struct imv_binds *binds) init_bind_node(&binds->bind_tree); } +void imv_binds_clear_key(struct imv_binds *binds, const struct list *keys) +{ + struct bind_node *node = &binds->bind_tree; + + for(size_t i = 0; i < keys->len; ++i) { + /* Traverse the trie to find the right node for the input keys */ + int child_index = list_find(node->suffixes, &compare_node_key, keys->items[i]); + if(child_index == -1) { + /* No such node, no more work to do */ + return; + } else { + node = node->suffixes->items[child_index]; + } + } + + /* We've now found the correct node for the input */ + + /* Clear the commands for this node */ + if(node->commands) { + list_deep_free(node->commands); + node->commands = NULL; + } +} + enum lookup_result { LOOKUP_PARTIAL, LOOKUP_INVALID, diff --git a/src/binds.h b/src/binds.h index a720fe1..5af7b5a 100644 --- a/src/binds.h +++ b/src/binds.h @@ -25,6 +25,9 @@ enum bind_result imv_binds_add(struct imv_binds *binds, const struct list *keys, /* Remove all key bindings */ void imv_binds_clear(struct imv_binds *binds); +/* Clear all bindings for a key*/ +void imv_binds_clear_key(struct imv_binds *binds, const struct list *keys); + /* Fetch the list of keys pressed so far */ const struct list *imv_bind_input_buffer(struct imv_binds *binds); |