[gtksourceview/wip/chergert/vim: 59/73] improve line motion a bit




commit baff38aeb0c68109915faf2a47e2d6537a69d25b
Author: Christian Hergert <chergert redhat com>
Date:   Sun Oct 24 09:35:47 2021 -0700

    improve line motion a bit

 gtksourceview/vim/gtk-source-vim-motion.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index d7f60618..6e704876 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -465,12 +465,26 @@ static gboolean
 motion_next_line (GtkTextIter        *iter,
                   GtkSourceVimMotion *state)
 {
-       if (!gtk_text_iter_ends_line (iter))
+       GtkTextIter before = *iter;
+
+       gtk_text_buffer_get_iter_at_line (gtk_text_iter_get_buffer (iter),
+                                         iter,
+                                         gtk_text_iter_get_line (iter) + 1);
+
+       if (gtk_text_iter_get_line (&before) == gtk_text_iter_get_line (iter))
        {
+               /* must be at end of file now. move to end of buffer
+                * but do not go past the last character.
+                */
                gtk_text_iter_forward_to_line_end (iter);
+               if (!gtk_text_iter_starts_line (iter))
+                       gtk_text_iter_backward_char (iter);
+               return gtk_text_iter_equal (iter, &before);
        }
 
-       return gtk_text_iter_forward_char (iter);
+       motion_line_first_char (iter, state);
+
+       return !gtk_text_iter_equal (iter, &before);
 }
 
 static gboolean


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