From: Daniel Carl Date: Sun, 24 Feb 2013 19:46:05 +0000 (+0100) Subject: Added search history (#8). X-Git-Url: https://git.owens.tech/style.css/style.css/git?a=commitdiff_plain;h=26a44e4b01a3eeffd3c004c0e4899f35e386b07b;p=vimb.git Added search history (#8). --- diff --git a/doc/vimp.1.txt b/doc/vimp.1.txt index 1c0a4c6..2307574 100644 --- a/doc/vimp.1.txt +++ b/doc/vimp.1.txt @@ -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" diff --git a/src/main.c b/src/main.c index 7d8f5c8..97d286f 100644 --- a/src/main.c +++ b/src/main.c @@ -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); }