Skip to content

Commit e314418

Browse files
committed
Clear keybinding from all keymaps (unbind) with bind generic <key> none
1 parent 683fdc8 commit e314418

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

NEWS.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Improvements:
1616
(hidden in default config). (#1318)
1717
- Show the selected commit in the blame view title window.
1818
- Improve the blob view experience.
19+
- Clear keybinding from all keymaps (unbind) with `bind generic <key> none`.
1920

2021
Bug fixes:
2122

contrib/git-flow.tigrc

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
# Get rid of default bindings for F, as that will be the entry point for all
2222
# git-flow related commands with this binding.
23-
bind main F none
2423
bind generic F none
2524

2625
# General

contrib/vim.tigrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ bind generic @k :?^@@
6060
bind generic @- :toggle diff-context -1
6161
bind generic @+ :toggle diff-context +1
6262

63-
bind status u none
64-
bind stage u none
63+
bind generic u none
6564
bind generic uu status-update
6665
bind generic ur status-revert
6766
bind generic um status-merge

doc/tigrc.5.adoc

+5-2
Original file line numberDiff line numberDiff line change
@@ -613,16 +613,19 @@ Or in the Git configuration files:
613613
--------------------------------------------------------------------------
614614
[tig "bind"]
615615
# 'unbind' the default quit key binding
616-
main = Q none
616+
generic = Q none
617617
# Cherry-pick current commit onto current branch
618-
generic = C !git cherry-pick %(commit)
618+
main = C !git cherry-pick %(commit)
619619
--------------------------------------------------------------------------
620620

621621
Keys are mapped by first searching the keybindings for the current view, then
622622
the keybindings for the *generic* keymap, and last the default keybindings.
623623
Thus, the view keybindings override the generic keybindings which override the
624624
built-in keybindings.
625625

626+
Clear keybinding (unbind) from all keymaps at once with bind *generic* 'key'
627+
*none*.
628+
626629
Keybindings at the line-entry prompt are typically governed by the readline
627630
library, and are configured separately in `~/.inputrc`. See 'readline(1)'.
628631
Tig respects but does not require an `$if tig` section in `~/.inputrc`.

src/keys.c

+27
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ keybinding_equals(const struct keybinding *keybinding, const struct key key[],
9494
return keybinding_matches(keybinding, key, keys, conflict_ptr);
9595
}
9696

97+
static enum status_code
98+
del_keybinding(const struct key key[], size_t keys)
99+
{
100+
bool found = false;
101+
size_t i;
102+
103+
for (i = 0; i < ARRAY_SIZE(keymaps); i++) {
104+
struct keymap *table = &keymaps[i];
105+
size_t j;
106+
107+
for (j = 0; j < table->size; j++)
108+
if (keybinding_equals(table->data[j], key, keys, NULL)) {
109+
found = true;
110+
free(table->data[j]);
111+
table->size--;
112+
for (; j < table->size; j++)
113+
table->data[j] = table->data[j + 1];
114+
table->data = realloc(table->data, table->size * sizeof(*table->data));
115+
}
116+
}
117+
118+
return found ? SUCCESS : error("No keybinding found for %s", get_key_name(key, keys, false));
119+
}
120+
97121
enum status_code
98122
add_keybinding(struct keymap *table, enum request request,
99123
const struct key key[], size_t keys)
@@ -103,6 +127,9 @@ add_keybinding(struct keymap *table, enum request request,
103127
bool conflict = false;
104128
size_t i;
105129

130+
if (is_generic_keymap(table) && request == REQ_NONE)
131+
return del_keybinding(key, keys);
132+
106133
for (i = 0; i < table->size; i++) {
107134
if (keybinding_equals(table->data[i], key, keys, &conflict)) {
108135
enum request old_request = table->data[i]->request;

test/help/user-command-test

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ Searching
5555
[-] main bindings
5656
Cursor navigation
5757
G move-last-line Move cursor to last line
58-
[help] - line 81 of 155 69%
58+
[help] - line 81 of 148 72%
5959
EOF

0 commit comments

Comments
 (0)