diff --git a/NEWS.adoc b/NEWS.adoc index 0295d9733..6a8b03c41 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -16,6 +16,7 @@ Improvements: (hidden in default config). (#1318) - Show the selected commit in the blame view title window. - Improve the blob view experience. + - Clear keybinding from all keymaps (unbind) with `bind generic none`. Bug fixes: diff --git a/contrib/git-flow.tigrc b/contrib/git-flow.tigrc index d276acd33..222878c30 100644 --- a/contrib/git-flow.tigrc +++ b/contrib/git-flow.tigrc @@ -20,7 +20,6 @@ # Get rid of default bindings for F, as that will be the entry point for all # git-flow related commands with this binding. -bind main F none bind generic F none # General diff --git a/contrib/vim.tigrc b/contrib/vim.tigrc index e6a1ac96a..78ed38e7c 100644 --- a/contrib/vim.tigrc +++ b/contrib/vim.tigrc @@ -60,8 +60,7 @@ bind generic @k :?^@@ bind generic @- :toggle diff-context -1 bind generic @+ :toggle diff-context +1 -bind status u none -bind stage u none +bind generic u none bind generic uu status-update bind generic ur status-revert bind generic um status-merge diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index b61af4fba..62515225f 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -613,9 +613,9 @@ Or in the Git configuration files: -------------------------------------------------------------------------- [tig "bind"] # 'unbind' the default quit key binding - main = Q none + generic = Q none # Cherry-pick current commit onto current branch - generic = C !git cherry-pick %(commit) + main = C !git cherry-pick %(commit) -------------------------------------------------------------------------- Keys are mapped by first searching the keybindings for the current view, then @@ -623,6 +623,9 @@ the keybindings for the *generic* keymap, and last the default keybindings. Thus, the view keybindings override the generic keybindings which override the built-in keybindings. +Clear keybinding (unbind) from all keymaps at once with bind *generic* 'key' +*none*. + Keybindings at the line-entry prompt are typically governed by the readline library, and are configured separately in `~/.inputrc`. See 'readline(1)'. Tig respects but does not require an `$if tig` section in `~/.inputrc`. diff --git a/src/keys.c b/src/keys.c index 0ac3e0bc9..dbf374507 100644 --- a/src/keys.c +++ b/src/keys.c @@ -94,6 +94,30 @@ keybinding_equals(const struct keybinding *keybinding, const struct key key[], return keybinding_matches(keybinding, key, keys, conflict_ptr); } +static enum status_code +del_keybinding(const struct key key[], size_t keys) +{ + bool found = false; + size_t i; + + for (i = 0; i < ARRAY_SIZE(keymaps); i++) { + struct keymap *table = &keymaps[i]; + size_t j; + + for (j = 0; j < table->size; j++) + if (keybinding_equals(table->data[j], key, keys, NULL)) { + found = true; + free(table->data[j]); + table->size--; + for (; j < table->size; j++) + table->data[j] = table->data[j + 1]; + table->data = realloc(table->data, table->size * sizeof(*table->data)); + } + } + + return found ? SUCCESS : error("No keybinding found for %s", get_key_name(key, keys, false)); +} + enum status_code add_keybinding(struct keymap *table, enum request request, const struct key key[], size_t keys) @@ -103,6 +127,9 @@ add_keybinding(struct keymap *table, enum request request, bool conflict = false; size_t i; + if (is_generic_keymap(table) && request == REQ_NONE) + return del_keybinding(key, keys); + for (i = 0; i < table->size; i++) { if (keybinding_equals(table->data[i], key, keys, &conflict)) { enum request old_request = table->data[i]->request; diff --git a/test/help/user-command-test b/test/help/user-command-test index 9de58285c..628a58f93 100755 --- a/test/help/user-command-test +++ b/test/help/user-command-test @@ -55,5 +55,5 @@ Searching [-] main bindings Cursor navigation G move-last-line Move cursor to last line -[help] - line 81 of 155 69% +[help] - line 81 of 148 72% EOF