[geany/geany-plugins] 891407: Merge pull request #847 from techee/excmd_history
Frank Lanitz
git-noreply at xxxxx
Fri May 3 16:27:06 UTC 2019
Branch: refs/heads/master
Author: Frank Lanitz <frank at frank.uvena.de>
Committer: GitHub <noreply at github.com>
Date: Fri, 03 May 2019 16:27:06 UTC
Commit: 891407e95b13546e9a55c5242c441833cf5b68b9
https://github.com/geany/geany-plugins/commit/891407e95b13546e9a55c5242c441833cf5b68b9
Log Message:
-----------
Merge pull request #847 from techee/excmd_history
vimode: Allow browsing ex command history using arrows
Modified Paths:
--------------
vimode/src/excmd-prompt.c
Modified: vimode/src/excmd-prompt.c
63 lines changed, 62 insertions(+), 1 deletions(-)
===================================================================
@@ -34,6 +34,8 @@
static GtkWidget *prompt;
static GtkWidget *entry;
static CmdContext *ctx;
+static GList *history;
+static gint history_pos;
static void close_prompt()
@@ -57,11 +59,66 @@ static gboolean on_prompt_key_press_event(GtkWidget *widget, GdkEventKey *event,
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
case GDK_KEY_ISO_Enter:
- excmd_perform(ctx, gtk_entry_get_text(GTK_ENTRY(entry)));
+ {
+ const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
+ GList *link = g_list_find_custom(history, text, (GCompareFunc)g_strcmp0);
+
+ if (link)
+ {
+ g_free(link->data);
+ history = g_list_remove_link(history, link);
+ }
+ if (g_strcmp0(text, ":") != 0)
+ history = g_list_prepend(history, g_strdup(text));
+
+ excmd_perform(ctx, text);
close_prompt();
+
+ return TRUE;
+ }
+
+ case GDK_KEY_Up:
+ case GDK_KEY_KP_Up:
+ case GDK_KEY_uparrow:
+ {
+ gint history_len = g_list_length(history);
+
+ if (history_pos == -1 && history_len > 0)
+ history_pos = 0;
+ else if (history_pos + 1 < history_len)
+ history_pos++;
+
+ if (history_pos != -1 && history_pos < history_len)
+ {
+ gchar *val = g_list_nth_data(history, history_pos);
+ gtk_entry_set_text(GTK_ENTRY(entry), val);
+ gtk_editable_set_position(GTK_EDITABLE(entry), strlen(val));
+ }
+
return TRUE;
+ }
+
+ case GDK_KEY_Down:
+ case GDK_KEY_KP_Down:
+ case GDK_KEY_downarrow:
+ {
+ const gchar *val;
+
+ if (history_pos == -1)
+ return TRUE;
+
+ history_pos--;
+
+ val = history_pos == -1 ? ":" : g_list_nth_data(history, history_pos);
+ gtk_entry_set_text(GTK_ENTRY(entry), val);
+ gtk_editable_set_position(GTK_EDITABLE(entry), strlen(val));
+
+ return TRUE;
+ }
}
+ history_pos = -1;
+
return FALSE;
}
@@ -87,6 +144,8 @@ void ex_prompt_init(GtkWidget *parent_window, CmdContext *c)
ctx = c;
+ history = NULL;
+
/* prompt */
prompt = g_object_new(GTK_TYPE_WINDOW,
"decorated", FALSE,
@@ -128,6 +187,7 @@ static void position_prompt(void)
void ex_prompt_show(const gchar *val)
{
+ history_pos = -1;
gtk_widget_show(prompt);
position_prompt();
gtk_entry_set_text(GTK_ENTRY(entry), val);
@@ -138,4 +198,5 @@ void ex_prompt_show(const gchar *val)
void ex_prompt_cleanup(void)
{
gtk_widget_destroy(prompt);
+ g_list_free_full(history, g_free);
}
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Plugins-Commits
mailing list