[gtksourceview/wip/chergert/vim] add line end w/ \n



commit f5a5fea061f5b2b3bd92bce36f82f283e249e31f
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 28 14:17:20 2021 -0700

    add line end w/ \n

 gtksourceview/vim/gtk-source-vim-motion.c | 33 +++++++++++++++++++++++++++++++
 gtksourceview/vim/gtk-source-vim-motion.h |  1 +
 2 files changed, 34 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index d9188f9a..8f1c955f 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -1469,6 +1469,39 @@ gtk_source_vim_motion_new_forward_char (void)
        return GTK_SOURCE_VIM_STATE (self);
 }
 
+static gboolean
+motion_forward_line_end (GtkTextIter        *iter,
+                         GtkSourceVimMotion *self)
+{
+       /* this version does not try to stay off the \n char, it is
+        * primarily used to do line selections like `S`, `3S`, etc.
+        */
+       if (gtk_text_iter_is_end (iter))
+               return FALSE;
+
+       if (gtk_text_iter_ends_line (iter))
+       {
+               gtk_text_iter_forward_char (iter);
+
+               if (gtk_text_iter_ends_line (iter))
+                       return TRUE;
+       }
+
+       return gtk_text_iter_forward_to_line_end (iter);
+}
+
+GtkSourceVimState *
+gtk_source_vim_motion_new_line_end_with_nl (void)
+{
+       GtkSourceVimMotion *self;
+
+       self = g_object_new (GTK_SOURCE_TYPE_VIM_MOTION, NULL);
+       self->motion = motion_forward_line_end;
+       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 3ae0242a..9e324aca 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.h
+++ b/gtksourceview/vim/gtk-source-vim-motion.h
@@ -35,6 +35,7 @@ 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);


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