Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Sat, 04 May 2019 07:08:58 UTC Commit: 8516ce37644c6d6af5596ddde8cecaabea6ff1e1 https://github.com/geany/geany-plugins/commit/8516ce37644c6d6af5596ddde8ceca...
Log Message: ----------- vimode: Separate command and search history
Vi seems to use a separate history for commands (starting with ':') and searches (starting with '/' or '?'). Let's do the same.
Modified Paths: -------------- vimode/src/excmd-prompt.c
Modified: vimode/src/excmd-prompt.c 38 lines changed, 24 insertions(+), 14 deletions(-) =================================================================== @@ -34,7 +34,11 @@ static GtkWidget *prompt; static GtkWidget *entry; static CmdContext *ctx; + +static gchar cmd_first_char; static GPtrArray *history; +static GPtrArray *cmd_history; +static GPtrArray *search_history; static gint history_pos;
@@ -44,6 +48,16 @@ static void close_prompt() }
+static void set_prompt_text(const gchar *val) +{ + gchar *text = g_strconcat(" ", val, NULL); + text[0] = cmd_first_char; + gtk_entry_set_text(GTK_ENTRY(entry), text); + gtk_editable_set_position(GTK_EDITABLE(entry), strlen(text)); + g_free(text); +} + + static gboolean on_prompt_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer dummy) { switch (event->keyval) @@ -63,10 +77,10 @@ static gboolean on_prompt_key_press_event(GtkWidget *widget, GdkEventKey *event, guint index; const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
- if (g_ptr_array_find_with_equal_func(history, text, g_str_equal, &index)) + if (g_ptr_array_find_with_equal_func(history, text + 1, g_str_equal, &index)) g_ptr_array_remove_index(history, index); if (strlen(text) > 1) - g_ptr_array_add(history, g_strdup(text)); + g_ptr_array_add(history, g_strdup(text + 1));
excmd_perform(ctx, text); close_prompt(); @@ -84,11 +98,7 @@ static gboolean on_prompt_key_press_event(GtkWidget *widget, GdkEventKey *event, history_pos--;
if (history_pos != -1) - { - gchar *val = history->pdata[history_pos]; - gtk_entry_set_text(GTK_ENTRY(entry), val); - gtk_editable_set_position(GTK_EDITABLE(entry), strlen(val)); - } + set_prompt_text(history->pdata[history_pos]);
return TRUE; } @@ -97,8 +107,6 @@ static gboolean on_prompt_key_press_event(GtkWidget *widget, GdkEventKey *event, case GDK_KEY_KP_Down: case GDK_KEY_downarrow: { - const gchar *val; - if (history_pos == -1) return TRUE;
@@ -107,9 +115,7 @@ static gboolean on_prompt_key_press_event(GtkWidget *widget, GdkEventKey *event, else history_pos = -1;
- val = history_pos == -1 ? ":" : history->pdata[history_pos]; - gtk_entry_set_text(GTK_ENTRY(entry), val); - gtk_editable_set_position(GTK_EDITABLE(entry), strlen(val)); + set_prompt_text(history_pos == -1 ? "" : history->pdata[history_pos]);
return TRUE; } @@ -142,7 +148,8 @@ void ex_prompt_init(GtkWidget *parent_window, CmdContext *c)
ctx = c;
- history = g_ptr_array_new_with_free_func(g_free); + cmd_history = g_ptr_array_new_with_free_func(g_free); + search_history = g_ptr_array_new_with_free_func(g_free);
/* prompt */ prompt = g_object_new(GTK_TYPE_WINDOW, @@ -186,6 +193,8 @@ static void position_prompt(void) void ex_prompt_show(const gchar *val) { history_pos = -1; + cmd_first_char = val[0]; + history = cmd_first_char == ':' ? cmd_history : search_history; gtk_widget_show(prompt); position_prompt(); gtk_entry_set_text(GTK_ENTRY(entry), val); @@ -196,5 +205,6 @@ void ex_prompt_show(const gchar *val) void ex_prompt_cleanup(void) { gtk_widget_destroy(prompt); - g_ptr_array_free(history, TRUE); + g_ptr_array_free(cmd_history, TRUE); + g_ptr_array_free(search_history, TRUE); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org