[gtksourceview/wip/chergert/vim: 243/363] allow special down-1 movement for repeat chars




commit 44bab454cd9749a6156c220b8f2f5dbdee2ae8ff
Author: Christian Hergert <chergert redhat com>
Date:   Wed Nov 3 12:44:45 2021 -0700

    allow special down-1 movement for repeat chars
    
    things like yy or dd are really more like y0y or d0d and this makes that
    a bit easier to replicate.

 gtksourceview/vim/gtk-source-vim-motion.c | 25 +++++++++++++++++++++++++
 gtksourceview/vim/gtk-source-vim-motion.h |  2 ++
 2 files changed, 27 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index f16a4d06..ec9b4e2e 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -71,6 +71,11 @@ struct _GtkSourceVimMotion
         */
        int alter_count;
 
+       /* If this is specified, we want to treat it like a `j` but
+        * with the count subtracted by one. Useful for yy, dd, etc.
+        */
+       guint linewise_keyval;
+
        /* Apply the motion when leaving the state. This is useful
         * so that you can either capture a motion for future use
         * or simply apply it immediately.
@@ -1325,6 +1330,17 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
                }
        }
 
+       if (keyval != 0 && keyval == self->linewise_keyval)
+       {
+               self->motion = motion_next_line_visual_column;
+               self->inclusivity = EXCLUSIVE;
+               self->wise = LINEWISE;
+               self->alter_count = -1;
+               g_string_truncate (self->command_text, 0);
+               gtk_source_vim_state_pop (GTK_SOURCE_VIM_STATE (self));
+               return TRUE;
+       }
+
        switch (keyval)
        {
                case GDK_KEY_0:
@@ -1897,3 +1913,12 @@ gtk_source_vim_motion_new_down (int alter_count)
 
        return GTK_SOURCE_VIM_STATE (self);
 }
+
+void
+gtk_source_vim_motion_set_linewise_keyval (GtkSourceVimMotion *self,
+                                           guint               keyval)
+{
+       g_return_if_fail (GTK_SOURCE_IS_VIM_MOTION (self));
+
+       self->linewise_keyval = keyval;
+}
diff --git a/gtksourceview/vim/gtk-source-vim-motion.h b/gtksourceview/vim/gtk-source-vim-motion.h
index e74f5c27..3dda7eac 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.h
+++ b/gtksourceview/vim/gtk-source-vim-motion.h
@@ -43,6 +43,8 @@ GtkSourceVimState *gtk_source_vim_motion_new_previous_line_end     (void);
 GtkSourceVimState *gtk_source_vim_motion_new_forward_char          (void);
 GtkSourceVimState *gtk_source_vim_motion_new_down                  (int                 adjust_count);
 GtkSourceVimState *gtk_source_vim_motion_new_line_start            (void);
+void               gtk_source_vim_motion_set_linewise_keyval       (GtkSourceVimMotion *self,
+                                                                    guint               keyval);
 void               gtk_source_vim_motion_set_apply_on_leave        (GtkSourceVimMotion *self,
                                                                     gboolean            apply_on_leave);
 void               gtk_source_vim_motion_set_mark                  (GtkSourceVimMotion *self,


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