[gtksourceview/wip/chergert/vim: 24/73] start on insert mode




commit 29af42d2e8b5a25023197cfd572f90875007060c
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 21 17:01:55 2021 -0700

    start on insert mode

 gtksourceview/vim/gtk-source-vim-normal.c | 52 ++++++++++++++++++++++++++++---
 1 file changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index eeb9efb5..42bd6871 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include "gtk-source-vim-insert.h"
 #include "gtk-source-vim-normal.h"
 
 typedef gboolean (*KeyHandler) (GtkSourceVimNormal *self,
@@ -56,6 +57,17 @@ is_escape (guint           keyval,
                (keyval == GDK_KEY_bracketleft && (mods & GDK_CONTROL_MASK) != 0);
 }
 
+static gboolean
+gtk_source_vim_normal_bail (GtkSourceVimNormal *self)
+{
+       g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+
+       gtk_source_vim_state_beep (GTK_SOURCE_VIM_STATE (self));
+       gtk_source_vim_normal_clear (self);
+
+       return TRUE;
+}
+
 static gboolean
 key_handler_motion (GtkSourceVimNormal *self,
                     guint               keyval,
@@ -111,8 +123,43 @@ key_handler_command (GtkSourceVimNormal *self,
                     GdkModifierType     mods,
                     const char         *string)
 {
+       g_autoptr(GtkSourceVimState) new_state = NULL;
+
        g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
 
+       switch (keyval)
+       {
+               case GDK_KEY_i:
+                       new_state = gtk_source_vim_insert_new ();
+                       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), new_state);
+                       break;
+
+               case GDK_KEY_a:
+               case GDK_KEY_asciitilde:
+               case GDK_KEY_A:
+               case GDK_KEY_C:
+               case GDK_KEY_D:
+               case GDK_KEY_I:
+               case GDK_KEY_J:
+               case GDK_KEY_o:
+               case GDK_KEY_O:
+               case GDK_KEY_p:
+               case GDK_KEY_P:
+               case GDK_KEY_period:
+               case GDK_KEY_R:
+               case GDK_KEY_s:
+               case GDK_KEY_S:
+               case GDK_KEY_u:
+               case GDK_KEY_x:
+               case GDK_KEY_equal:
+               case GDK_KEY_plus:
+               case GDK_KEY_Y:
+                       break;
+
+               default:
+                       return gtk_source_vim_normal_bail (self);
+       }
+
        return FALSE;
 }
 
@@ -435,10 +482,7 @@ key_handler_initial (GtkSourceVimNormal *self,
        }
 
        if (self->handler == key_handler_initial)
-       {
-               gtk_source_vim_normal_clear (self);
-               return FALSE;
-       }
+               return gtk_source_vim_normal_bail (self);
 
        return self->handler (self, keyval, keycode, mods, string);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]