[gtksourceview/wip/chergert/vim: 126/363] add motion suitable for J




commit d2074f8cf7a7f4100eaf7a185a457ff6fdba2eff
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 28 21:59:22 2021 -0700

    add motion suitable for J

 gtksourceview/vim/gtk-source-vim-motion.c | 39 +++++++++++++++++++++++++------
 gtksourceview/vim/gtk-source-vim-motion.h | 27 ++++++++++-----------
 2 files changed, 46 insertions(+), 20 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index cc8ed105..4446bce2 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -1466,11 +1466,10 @@ gtk_source_vim_motion_new_forward_char (void)
 }
 
 static gboolean
-motion_line_end_with_nl (GtkTextIter        *iter,
-                         GtkSourceVimMotion *self)
+do_motion_line_end_with_nl (GtkTextIter *iter,
+                            int          apply_count,
+                            int          count)
 {
-       int count;
-
        /* This function has to take into account newlines so that we
         * can move and delete whole lines. It is extra complicated
         * because we can't actually move when we have an empty line.
@@ -1480,11 +1479,9 @@ motion_line_end_with_nl (GtkTextIter        *iter,
         * mismatch with VIM character movements.
         */
 
-       if (self->apply_count != 1)
+       if (apply_count != 1)
                return FALSE;
 
-       count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
-
        if (count == 1)
        {
                if (gtk_text_iter_ends_line (iter))
@@ -1501,6 +1498,22 @@ motion_line_end_with_nl (GtkTextIter        *iter,
        return TRUE;
 }
 
+static gboolean
+motion_line_end_with_nl (GtkTextIter        *iter,
+                         GtkSourceVimMotion *self)
+{
+       int count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
+       return do_motion_line_end_with_nl (iter, self->apply_count, count);
+}
+
+static gboolean
+motion_next_line_end_with_nl (GtkTextIter        *iter,
+                              GtkSourceVimMotion *self)
+{
+       int count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
+       return do_motion_line_end_with_nl (iter, self->apply_count, count + 1);
+}
+
 GtkSourceVimState *
 gtk_source_vim_motion_new_line_end_with_nl (void)
 {
@@ -1513,6 +1526,18 @@ gtk_source_vim_motion_new_line_end_with_nl (void)
        return GTK_SOURCE_VIM_STATE (self);
 }
 
+GtkSourceVimState *
+gtk_source_vim_motion_new_next_line_end_with_nl (void)
+{
+       GtkSourceVimMotion *self;
+
+       self = g_object_new (GTK_SOURCE_TYPE_VIM_MOTION, NULL);
+       self->motion = motion_next_line_end_with_nl;
+       self->inclusivity = EXCLUSIVE;
+
+       return GTK_SOURCE_VIM_STATE (self);
+}
+
 GtkSourceVimState *
 gtk_source_vim_motion_new_none (void)
 {
diff --git a/gtksourceview/vim/gtk-source-vim-motion.h b/gtksourceview/vim/gtk-source-vim-motion.h
index 9e324aca..e20cb924 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.h
+++ b/gtksourceview/vim/gtk-source-vim-motion.h
@@ -31,18 +31,19 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GtkSourceVimMotion, gtk_source_vim_motion, GTK_SOURCE, VIM_MOTION, GtkSourceVimState)
 
-GtkSourceVimState *gtk_source_vim_motion_new                   (void);
-GtkSourceVimState *gtk_source_vim_motion_new_none              (void);
-GtkSourceVimState *gtk_source_vim_motion_new_first_char        (void);
-GtkSourceVimState *gtk_source_vim_motion_new_line_end          (void);
-GtkSourceVimState *gtk_source_vim_motion_new_line_end_with_nl  (void);
-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_line_start        (void);
-void               gtk_source_vim_motion_set_apply_on_leave    (GtkSourceVimMotion *self,
-                                                                gboolean            apply_on_leave);
-gboolean           gtk_source_vim_motion_apply                 (GtkSourceVimMotion *self,
-                                                                GtkTextIter        *iter,
-                                                                gboolean            apply_inclusive);
+GtkSourceVimState *gtk_source_vim_motion_new                       (void);
+GtkSourceVimState *gtk_source_vim_motion_new_none                  (void);
+GtkSourceVimState *gtk_source_vim_motion_new_first_char            (void);
+GtkSourceVimState *gtk_source_vim_motion_new_line_end              (void);
+GtkSourceVimState *gtk_source_vim_motion_new_line_end_with_nl      (void);
+GtkSourceVimState *gtk_source_vim_motion_new_next_line_end_with_nl (void);
+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_line_start            (void);
+void               gtk_source_vim_motion_set_apply_on_leave        (GtkSourceVimMotion *self,
+                                                                    gboolean            apply_on_leave);
+gboolean           gtk_source_vim_motion_apply                     (GtkSourceVimMotion *self,
+                                                                    GtkTextIter        *iter,
+                                                                    gboolean            apply_inclusive);
 
 G_END_DECLS


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