summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Koutcher <thomas.koutcher@online.fr>2024-03-25 19:30:59 +0100
committerThomas Koutcher <thomas.koutcher@online.fr>2024-03-27 19:37:28 +0100
commite31441834c6eac3af4e2dc20c68626b3a77bdb54 (patch)
tree1bf24158af86905c92db7959f5dd855d293bbb24
parent683fdc86374da5ce03ddabc271157e601a8fda0b (diff)
Clear keybinding from all keymaps (unbind) with `bind generic <key> none`
-rw-r--r--NEWS.adoc1
-rw-r--r--contrib/git-flow.tigrc1
-rw-r--r--contrib/vim.tigrc3
-rw-r--r--doc/tigrc.5.adoc7
-rw-r--r--src/keys.c27
-rwxr-xr-xtest/help/user-command-test2
6 files changed, 35 insertions, 6 deletions
diff --git a/NEWS.adoc b/NEWS.adoc
index 0295d973..6a8b03c4 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 <key> none`.
Bug fixes:
diff --git a/contrib/git-flow.tigrc b/contrib/git-flow.tigrc
index d276acd3..222878c3 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 e6a1ac96..78ed38e7 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 b61af4fb..62515225 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 0ac3e0bc..dbf37450 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 9de58285..628a58f9 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