From 30be6b0b2a9bf61d2e20ccaad3280bdde386432b Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Mon, 12 Nov 2012 19:08:53 +0100
Subject: [PATCH] Added macro to get only main modes.

---
 src/keybind.c | 6 ++++--
 src/main.c    | 5 ++---
 src/main.h    | 5 +++--
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/keybind.c b/src/keybind.c
index 6ba3a5b..1dff1c5 100644
--- a/src/keybind.c
+++ b/src/keybind.c
@@ -208,13 +208,15 @@ static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* e
     }
 
     /* TODO should we use a command for that too? */
-    if (event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab) {
+    if (CLEAN_MODE(vp.state.mode) == VP_MODE_COMMAND
+        && (event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab)
+    ) {
         completion_complete(event->keyval == GDK_ISO_Left_Tab);
         return TRUE;
     }
 
     /* check for keybinding */
-    GSList* link = keybind_find(vp.state.mode, vp.state.modkey,
+    GSList* link = keybind_find(CLEAN_MODE(vp.state.mode), vp.state.modkey,
             (CLEAN(event->state) & ~irrelevant), keyval);
 
     if (link) {
diff --git a/src/main.c b/src/main.c
index 87eee77..49407cd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -268,8 +268,7 @@ void vp_clean_up(void)
 static gboolean vp_hide_message(void)
 {
     /* do not clean in command mode */
-    /* TODO add a CLEAN_MODE macro to get only the main modes */
-    if (vp.state.mode & VP_MODE_COMMAND) {
+    if (CLEAN_MODE(vp.state.mode) == VP_MODE_COMMAND) {
         return FALSE;
     }
 
@@ -294,7 +293,7 @@ gboolean vp_set_mode(const Arg* arg)
     vp.state.mode = arg->i;
     vp.state.modkey = vp.state.count  = 0;
 
-    switch (arg->i) {
+    switch (CLEAN_MODE(arg->i)) {
         case VP_MODE_NORMAL:
             gtk_widget_grab_focus(GTK_WIDGET(vp.gui.webview));
             break;
diff --git a/src/main.h b/src/main.h
index 5d84953..a0592c0 100644
--- a/src/main.h
+++ b/src/main.h
@@ -44,6 +44,7 @@
 #endif
 
 #define GET_TEXT() (gtk_entry_get_text(GTK_ENTRY(vp.gui.inputbox)))
+#define CLEAN_MODE(mode) ((mode) & ~(VP_MODE_COMPLETE))
 
 /* enums */
 typedef enum _vp_mode {
@@ -51,8 +52,8 @@ typedef enum _vp_mode {
     VP_MODE_COMMAND       = 1<<1,
     VP_MODE_PATH_THROUGH  = 1<<2,
     VP_MODE_INSERT        = 1<<3,
-    VP_MODE_COMPLETE      = 1<<4,
-    VP_MODE_SEARCH        = 1<<5,
+    VP_MODE_SEARCH        = 1<<4,
+    VP_MODE_COMPLETE      = 1<<5,
 } Mode;
 
 enum {
-- 
2.20.1