Added search history (#8).
authorDaniel Carl <danielcarl@gmx.de>
Sun, 24 Feb 2013 19:46:05 +0000 (20:46 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 24 Feb 2013 19:56:36 +0000 (20:56 +0100)
doc/vimp.1.txt
src/main.c

index 1c0a4c6..2307574 100644 (file)
@@ -285,7 +285,12 @@ Reset the zoomlevel to the default value.
 .TP
 .BI [ N "]command-hist-prev, [" N "]command-hist-next"
 Prints the previous or next cammand from history into inputbox. If there is
-already text in the input box this will be used to get history items.
+already text in the input box this will be used to get history items. A
+command is not a internal command, but every string entered into inputbox that
+begins with \fI[:/?]\fP. So the history contains real commands and search queries.
+.br
+Note that the history distinguishes between '/query' and '?query' what's not
+what the vim editor does.
 .SS Misc
 .TP
 .BI [ N "]search-forward, [" N "]search-backward"
index 7d8f5c8..97d286f 100644 (file)
@@ -151,7 +151,8 @@ static void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window, gpointer
 static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data)
 {
     const char* text;
-    char* command = NULL;
+    gboolean hist_save = FALSE;
+    char* command  = NULL;
     guint16 length = gtk_entry_get_text_length(entry);
     Gui* gui = &vp.gui;
 
@@ -173,24 +174,27 @@ static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data)
      * content of inputbox */
     command = g_strdup((text));
 
+    Arg a;
     switch (*text) {
         case '/':
         case '?':
-            {
-                Arg a = {*text == '/' ? VP_SEARCH_FORWARD : VP_SEARCH_BACKWARD, (command + 1)};
-                command_search(&a);
-            }
+            a.i = *text == '/' ? VP_SEARCH_FORWARD : VP_SEARCH_BACKWARD;
+            a.s = (command + 1);
+            command_search(&a);
+            hist_save = TRUE;
             break;
 
         case ':':
             completion_clean();
             vp_process_input((command + 1));
-
-            /* save the command together with the first char in history */
-            history_append(command);
-
+            hist_save = TRUE;
             break;
     }
+
+    if (hist_save) {
+        /* save the command in history */
+        history_append(command);
+    }
     g_free(command);
 }