[gtksourceview/wip/chergert/vim: 160/363] yank with motion




commit 833128c2728534b30f1230ef1937af70b420f60d
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]