search_off(): properly clear cl->hist_word ..

This commit is contained in:
wdlkmpx 2020-12-29 16:32:47 +08:00
parent e84930778a
commit d41ba7df77
2 changed files with 8 additions and 2 deletions

View File

@ -788,6 +788,10 @@ down_history(GtkCompletionLine* cl)
static void search_off (GtkCompletionLine* cl)
{
cl->hist_search_mode = FALSE;
int i;
for (i = 0; i < MAX_HISTWORD_CHARS; i++) {
cl->hist_word[i] = 0;
}
g_signal_emit_by_name (G_OBJECT(cl), "search_mode");
history_unset_current (cl->hist);
}
@ -1084,7 +1088,7 @@ on_key_press(GtkCompletionLine *cl, GdkEventKey *event, gpointer data)
// event->string = char: 'c' 'd'
cl->hist_word[cl->hist_word_count] = event->string[0];
cl->hist_word_count++;
if (cl->hist_word_count <= 1000) {
if (cl->hist_word_count < MAX_HISTWORD_CHARS) {
search_history (cl, 0);
}
return TRUE; /* stop signal emission */

View File

@ -33,6 +33,8 @@ extern "C"
typedef struct _GtkCompletionLine GtkCompletionLine;
typedef struct _GtkCompletionLineClass GtkCompletionLineClass;
#define MAX_HISTWORD_CHARS 1024
struct _GtkCompletionLine
{
GtkEntry parent;
@ -46,7 +48,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 */
char hist_word[MAX_HISTWORD_CHARS]; /* history search: word that is being typed */
int hist_word_count; /* history search: word that is being typed */
int tabtimeout;