From: Daniel Carl Date: Mon, 12 Nov 2012 19:47:49 +0000 (+0100) Subject: Changed format to specify key bindings. X-Git-Url: https://git.owens.tech/assets/static/git-favicon.png/assets/static/git-favicon.png/git?a=commitdiff_plain;h=540d4c33a51b8281d77793862a18621a9e1cf497;p=vimb.git Changed format to specify key bindings. Use to specifiy modmask and keyval together. With this approach it's easier to parse and we can simply extend to use also keyval like . --- diff --git a/doc/config b/doc/config index defc41f..9a5a0e1 100644 --- a/doc/config +++ b/doc/config @@ -4,15 +4,15 @@ nmap : input nmap o inputopen nmap O inputopencurrent nmap d quit -nmap o back -nmap i forward +nmap back +nmap forward nmap r reload nmap R reload! -nmap c stop -nmap f pagedown -nmap b pageup -nmap d halfpagedown -nmap u halfpageup +nmap stop +nmap pagedown +nmap pageup +nmap halfpagedown +nmap halfpageup nmap gg jumptop nmap G jumpbottom nmap 0 jumpleft diff --git a/src/keybind.c b/src/keybind.c index 1dff1c5..4eaad39 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -28,6 +28,7 @@ static GString* modkeys = NULL; static GSList* keybind_find(int mode, guint modkey, guint modmask, guint keyval); static void keybind_str_to_keybind(gchar* str, Keybind* key); static guint keybind_str_to_modmask(const gchar* str); +static guint keybind_str_to_value(const gchar* str); static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* event); @@ -124,6 +125,9 @@ static GSList* keybind_find(int mode, guint modkey, guint modmask, guint keyval) return NULL; } +/** + * Configures the given keybind by also given string. + */ static void keybind_str_to_keybind(gchar* str, Keybind* keybind) { gchar** string = NULL; @@ -134,23 +138,43 @@ static void keybind_str_to_keybind(gchar* str, Keybind* keybind) } g_strstrip(str); - /* [modkey[]]keyval */ - string = g_strsplit_set(str, "<>", 3); - len = g_strv_length(string); - - if (len == 1) { /* no modmask set */ - if (strlen(string[0]) == 2) { - keybind->modkey = string[0][0]; - keybind->keyval = string[0][1]; + /* [modkey]keyval + * - modkey is a single char + * - keval can be a single char, , , */ + keybind->modkey = 0; + if (strlen(str) == 1) { + /* only a single simple key set like "q" */ + keybind->keyval = str[0]; + } else if (strlen(str) == 2) { + /* modkey with simple key given like "gf" */ + keybind->modkey = str[0]; + keybind->keyval = str[1]; + } else { + /* special handling for shift tab */ + /* TODO find a better solution for such cases */ + if (g_ascii_strcasecmp(str, "") == 0) { + keybind->keyval = GDK_ISO_Left_Tab; + return; + } + /* keybind has keys like "" or */ + if (str[0] == '<') { + /* no modkey set */ + string = g_strsplit_set(str, "<->", 4); } else { - keybind->keyval = string[0][0]; + keybind->modkey = str[0]; + string = g_strsplit_set(str + 1, "<->", 4); + } + len = g_strv_length(string); + if (len == 4) { + /* key with modmask like */ + keybind->modmask = keybind_str_to_modmask(string[1]); + keybind->keyval = keybind_str_to_value(string[2]); + } else if (len == 3) { + /* key without modmask like */ + keybind->keyval = keybind_str_to_value(string[1]); } - } else { /* contains modmask */ - keybind->modkey = (string[0][0] != '\0') ? string[0][0] : 0; - keybind->modmask = keybind_str_to_modmask(string[1]); - keybind->keyval = string[2][0]; + g_strfreev(string); } - g_strfreev(string); } static guint keybind_str_to_modmask(const gchar* str) @@ -165,6 +189,15 @@ static guint keybind_str_to_modmask(const gchar* str) return 0; } +static guint keybind_str_to_value(const gchar* str) +{ + if (g_ascii_strcasecmp(str, "tab") == 0) { + return GDK_Tab; + } + + return str[0]; +} + static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* event) { GdkModifierType irrelevant; @@ -207,6 +240,7 @@ static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* e } } +#if 0 /* TODO should we use a command for that too? */ if (CLEAN_MODE(vp.state.mode) == VP_MODE_COMMAND && (event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab) @@ -214,6 +248,7 @@ static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* e completion_complete(event->keyval == GDK_ISO_Left_Tab); return TRUE; } +#endif /* check for keybinding */ GSList* link = keybind_find(CLEAN_MODE(vp.state.mode), vp.state.modkey,