[gtksourceview/wip/chergert/vim] yank with motion



commit fe1cd7d06dcccf35d093c2f96764638f155d9563
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 29 17:23:24 2021 -0700

    yank with motion

 gtksourceview/vim/gtk-source-vim-normal.c | 35 ++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index ee03ef99..baf49342 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -606,8 +606,41 @@ key_handler_yank (GtkSourceVimNormal *self,
                   GdkModifierType     mods,
                   const char         *string)
 {
+       GtkSourceVimState *new_state;
+       GtkSourceVimState *selection_motion;
+       GtkSourceVimState *insert_motion;
+
        g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
 
+       switch (keyval)
+       {
+               case GDK_KEY_y:
+                       gtk_source_vim_normal_begin_command (self,
+                                                            gtk_source_vim_motion_new_line_end_with_nl (),
+                                                            gtk_source_vim_motion_new_line_start (),
+                                                            ":yank");
+                       return TRUE;
+
+               default:
+                       break;
+       }
+
+       selection_motion = gtk_source_vim_motion_new_none ();
+
+       insert_motion = gtk_source_vim_motion_new ();
+       gtk_source_vim_motion_set_apply_on_leave (GTK_SOURCE_VIM_MOTION (insert_motion), FALSE);
+
+       new_state = g_object_new (GTK_SOURCE_TYPE_VIM_COMMAND,
+                                 "command", ":yank",
+                                 "selection-motion", selection_motion,
+                                 NULL);
+
+       g_object_unref (selection_motion);
+
+       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), new_state);
+       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (new_state), insert_motion);
+       gtk_source_vim_state_synthesize (GTK_SOURCE_VIM_STATE (insert_motion), keyval, mods);
+
        return TRUE;
 }
 
@@ -867,7 +900,7 @@ key_handler_initial (GtkSourceVimNormal *self,
 
                        case GDK_KEY_y:
                                self->handler = key_handler_yank;
-                               break;
+                               return TRUE;
 
                        case GDK_KEY_d:
                                self->handler = key_handler_delete;


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