[gtksourceview/wip/chergert/vim] implement c or C to insert from visual mode



commit 04f575c2c431ad2a612dd54386eb58d1d97731e9
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 2 16:04:16 2021 -0700

    implement c or C to insert from visual mode

 gtksourceview/vim/gtk-source-vim-visual.c | 38 +++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index f2c6f983..78d0d221 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -25,6 +25,7 @@
 
 #include "gtk-source-vim-command.h"
 #include "gtk-source-vim-delete.h"
+#include "gtk-source-vim-insert.h"
 #include "gtk-source-vim-motion.h"
 #include "gtk-source-vim-visual.h"
 
@@ -348,6 +349,35 @@ gtk_source_vim_visual_try_motion (GtkSourceVimVisual *self,
        return TRUE;
 }
 
+static gboolean
+gtk_source_vim_visual_begin_insert (GtkSourceVimVisual *self)
+{
+       GtkSourceVimState *insert;
+       GtkSourceVimMotion *motion;
+
+       g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
+
+       motion = GTK_SOURCE_VIM_MOTION (gtk_source_vim_motion_new_none ());
+       insert = gtk_source_vim_insert_new ();
+
+       if (self->mode == GTK_SOURCE_VIM_VISUAL_LINE)
+       {
+               gtk_source_vim_insert_set_suffix (GTK_SOURCE_VIM_INSERT (insert), "\n");
+       }
+
+       gtk_source_vim_insert_set_at (GTK_SOURCE_VIM_INSERT (insert), GTK_SOURCE_VIM_INSERT_HERE);
+       gtk_source_vim_insert_set_motion (GTK_SOURCE_VIM_INSERT (insert), motion);
+       gtk_source_vim_insert_set_selection_motion (GTK_SOURCE_VIM_INSERT (insert), motion);
+       gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
+       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), insert);
+
+       g_set_object (&self->command, insert);
+
+       g_object_unref (motion);
+
+       return TRUE;
+}
+
 static gboolean
 key_handler_g (GtkSourceVimVisual *self,
               guint               keyval,
@@ -421,6 +451,10 @@ key_handler_initial (GtkSourceVimVisual *self,
                        self->handler = key_handler_g;
                        return TRUE;
 
+               case GDK_KEY_c:
+               case GDK_KEY_C:
+                       return gtk_source_vim_visual_begin_insert (self);
+
                default:
                        break;
        }
@@ -518,6 +552,10 @@ gtk_source_vim_visual_resume (GtkSourceVimState *state,
                g_object_unref (chained);
        }
 
+       if (GTK_SOURCE_IS_VIM_INSERT (from))
+       {
+               gtk_source_vim_state_pop (state);
+       }
 }
 
 static void


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