From: Daniel Carl Date: Thu, 13 Jun 2013 21:56:16 +0000 (+0200) Subject: Changed :?map commands to act like in vim. X-Git-Url: https://git.owens.tech/style.css/style.css/git?a=commitdiff_plain;h=fbdb3249e4e86d02b5b131c56b32cb7b68b43dd9;p=vimb.git Changed :?map commands to act like in vim. If a key sequence is added that already where bound to a command, the previous keybinding will be removed before the new keybinding is created. --- diff --git a/doc/vimb.1.txt b/doc/vimb.1.txt index a494846..ec85efa 100644 --- a/doc/vimb.1.txt +++ b/doc/vimb.1.txt @@ -183,8 +183,7 @@ Example: "cunmap " To remove this keybinding use. If a keybinding is added, for the same key-sequence like another keybinding, -the later added have precedence. If a keybinding is removed only that with the -highest precedence will be removed and all other will still be active. +the previous keybinding will be removed. .TP .B nmap Add a keybinding used in Normal Mode. diff --git a/src/keybind.c b/src/keybind.c index 3cef457..40a4360 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -27,6 +27,7 @@ extern VbCore vb; static GSList *keys; static GString *modkeys; +static void keybind_remove(Keybind *kb); static void rebuild_modkeys(void); static GSList *find(int mode, guint modkey, guint modmask, guint keyval); static void string_to_keybind(char *str, Keybind *key); @@ -75,6 +76,9 @@ gboolean keybind_add_from_string(char *keystring, const char *command, const Mod string_to_keybind(keystring, keybind); + /* remove possible existing keybinding */ + keybind_remove(keybind); + /* add the keybinding to the list */ keys = g_slist_prepend(keys, keybind); @@ -98,17 +102,22 @@ gboolean keybind_remove_from_string(char *str, const Mode mode) /* fill the keybind with data from given string */ string_to_keybind(str, &keybind); - GSList *link = find(keybind.mode, keybind.modkey, keybind.modmask, keybind.keyval); + keybind_remove(&keybind); + + return true; +} + +static void keybind_remove(Keybind *kb) +{ + GSList *link = find(kb->mode, kb->modkey, kb->modmask, kb->keyval); if (link) { free_keybind((Keybind*)link->data); keys = g_slist_delete_link(keys, link); + if (kb->modkey && strchr(modkeys->str, kb->modkey)) { + /* remove eventually no more used modkeys */ + rebuild_modkeys(); + } } - - if (keybind.modkey && strchr(modkeys->str, keybind.modkey) != NULL) { - /* remove eventually no more used modkeys */ - rebuild_modkeys(); - } - return true; } /**