[gtksourceview/wip/chergert/vim: 308/363] add simple completion for command bar
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 308/363] add simple completion for command bar
- Date: Mon, 8 Nov 2021 19:53:54 +0000 (UTC)
commit 3c07f606bf5e02f3b15848b4a33933e53e2f67b4
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 5 09:02:30 2021 -0700
add simple completion for command bar
gtksourceview/vim/gtk-source-vim-command-bar.c | 35 +++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command-bar.c b/gtksourceview/vim/gtk-source-vim-command-bar.c
index 3d7ccb8b..bd7020c4 100644
--- a/gtksourceview/vim/gtk-source-vim-command-bar.c
+++ b/gtksourceview/vim/gtk-source-vim-command-bar.c
@@ -96,6 +96,34 @@ move_history (GtkSourceVimCommandBar *self,
g_string_append (self->buffer, g_ptr_array_index (history, self->history_pos));
}
+static void
+complete_command (GtkSourceVimCommandBar *self,
+ const char *prefix)
+{
+ static const char *commands[] = {
+ ":colorscheme",
+ ":write",
+ ":quit",
+ ":edit",
+ ":open",
+ ":file",
+ ":set",
+ };
+
+ g_assert (GTK_SOURCE_IS_VIM_COMMAND_BAR (self));
+
+ for (guint i = 0; i < G_N_ELEMENTS (commands); i++)
+ {
+ if (g_str_has_prefix (commands[i], prefix))
+ {
+ g_string_truncate (self->buffer, 0);
+ g_string_append (self->buffer, commands[i]);
+ g_string_append_c (self->buffer, ' ');
+ break;
+ }
+ }
+}
+
static void
do_execute (GtkSourceVimCommandBar *self,
const char *command)
@@ -152,17 +180,18 @@ gtk_source_vim_command_bar_handle_keypress (GtkSourceVimState *state,
case GDK_KEY_Tab:
case GDK_KEY_KP_Tab:
- break;
+ complete_command (self, self->buffer->str);
+ return TRUE;
case GDK_KEY_Up:
case GDK_KEY_KP_Up:
move_history (self, -1);
- break;
+ return TRUE;
case GDK_KEY_Down:
case GDK_KEY_KP_Down:
move_history (self, 1);
- break;
+ return TRUE;
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]