"!": history search mode that matches only the start of strings
The gtk entry must be emtpy before pressing "!" It enters a special (history) search mode that only matches the start of strings, a reverse search hit CTRL-R or CTRL-S to extend search backwards or forwards
This commit is contained in:
parent
0bd21c2b90
commit
68282dd4c0
|
@ -23,7 +23,8 @@ Features
|
|||
|
||||
* CTRL-R to search backwards through history.
|
||||
* CTRL-S to search forward through history.
|
||||
* Esc to cancel search (only once).
|
||||
* "!" enters a special search mode, matching only the start of strings.
|
||||
-- Esc to cancel search (only once).
|
||||
|
||||
* URL handlers allowing you to enter lines like "http://www.google.com"
|
||||
to start your favorite browser on www.google.com.
|
||||
|
|
|
@ -45,7 +45,7 @@ The command to run when Ctrl+Enter is pressed with a command entered. The entere
|
|||
see /etc/gmrunrc for more info
|
||||
.TP
|
||||
.B History
|
||||
Number of entered commands which should be kept in gmrun's history(~/.gmrun_history). Using the Up and Down arrow keys within the gmrun window will cycle through the history. You can search backwards through the history with Ctrl+R, and forward with Ctrl+S. To cancel a search, hit the \fIESC\fP key. Otherwise, after you have found the history item you wish to run, hit Enter.
|
||||
Number of entered commands which should be kept in gmrun's history(~/.gmrun_history). Using the Up and Down arrow keys within the gmrun window will cycle through the history. You can search backwards through the history with Ctrl+R, and forward with Ctrl+S. Hit "!" to enter a special search that matches only the start of strings. To cancel a search, hit the \fIESC\fP key. Otherwise, after you have found the history item you wish to run, hit Enter.
|
||||
.TP
|
||||
.B ShowLast
|
||||
Whether to show the last command as initial text, or an empty textarea (1 or 0).
|
||||
|
|
|
@ -807,18 +807,28 @@ static void search_history (GtkCompletionLine* cl, int next)
|
|||
history_current_item = history_search_first_func (cl->hist);
|
||||
}
|
||||
|
||||
int search_str_len = 0;
|
||||
int search_match_start = cl->hist_search_match_start;
|
||||
if (search_match_start) { /* ! */
|
||||
search_str_len = strlen (search_str);
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
const char * s = NULL;
|
||||
if (history_current_item) {
|
||||
s = strstr (history_current_item, search_str);
|
||||
if (search_match_start) { /* ! */
|
||||
if (strncmp (history_current_item, search_str, search_str_len) == 0) {
|
||||
s = history_current_item;
|
||||
}
|
||||
} else { /* CTRL-R / CTRL-S */
|
||||
s = strstr (history_current_item, search_str);
|
||||
}
|
||||
}
|
||||
if (s) {
|
||||
if (strstr (history_current_item, search_str)) {
|
||||
gtk_entry_set_text (GTK_ENTRY(cl), history_current_item);
|
||||
g_signal_emit_by_name (G_OBJECT(cl), "search_letter");
|
||||
return;
|
||||
}
|
||||
gtk_entry_set_text (GTK_ENTRY(cl), history_current_item);
|
||||
g_signal_emit_by_name (G_OBJECT(cl), "search_letter");
|
||||
return;
|
||||
}
|
||||
history_current_item = history_search_next_func (cl->hist);
|
||||
if (history_current_item == NULL) {
|
||||
|
@ -1006,6 +1016,7 @@ on_key_press(GtkCompletionLine *cl, GdkEventKey *event, gpointer data)
|
|||
if (cl->hist_search_mode == FALSE) {
|
||||
gtk_entry_set_text (GTK_ENTRY (cl), "");
|
||||
cl->hist_search_mode = TRUE;
|
||||
cl->hist_search_match_start = FALSE;
|
||||
cl->hist_word[0] = 0;
|
||||
cl->hist_word_count = 0;
|
||||
g_signal_emit_by_name(G_OBJECT(cl), "search_mode");
|
||||
|
@ -1016,6 +1027,22 @@ on_key_press(GtkCompletionLine *cl, GdkEventKey *event, gpointer data)
|
|||
return TRUE; /* stop signal emission */
|
||||
} else goto ordinary;
|
||||
|
||||
case GDK_KEY_exclam:
|
||||
if (cl->hist_search_mode == FALSE) {
|
||||
const char * entry_text = gtk_entry_get_text (GTK_ENTRY (cl));
|
||||
if (!*entry_text) {
|
||||
history_search_first_func = history_last;
|
||||
history_search_next_func = history_prev;
|
||||
cl->hist_search_mode = TRUE;
|
||||
cl->hist_search_match_start = TRUE;
|
||||
cl->hist_word[0] = 0;
|
||||
cl->hist_word_count = 0;
|
||||
g_signal_emit_by_name (G_OBJECT(cl), "search_mode");
|
||||
return TRUE; /* stop signal emission */
|
||||
}
|
||||
}
|
||||
goto ordinary;
|
||||
|
||||
case GDK_KEY_BackSpace:
|
||||
if (cl->hist_search_mode == TRUE) {
|
||||
if (cl->hist_word[0]) {
|
||||
|
|
|
@ -45,6 +45,7 @@ struct _GtkCompletionLine
|
|||
|
||||
HistoryFile * hist;
|
||||
gboolean hist_search_mode;
|
||||
gboolean hist_search_match_start;
|
||||
char hist_word[1024]; /* history search: word that is being typed */
|
||||
int hist_word_count; /* history search: word that is being typed */
|
||||
|
||||
|
|
Loading…
Reference in New Issue