[gtksourceview/wip/chergert/vim: 56/293] fix some char motion




commit 191705ca4f3e6291bc98c06a3b2dc05fa9df6286
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 23 14:42:48 2021 -0700

    fix some char motion

 gtksourceview/vim/gtk-source-vim-motion.c | 36 ++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 40fcdc4a..3a70e925 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -376,26 +376,52 @@ static gboolean
 motion_forward_char (GtkTextIter   *iter,
                      GtkSourceView *view)
 {
-       return gtk_text_iter_forward_char (iter);
+       GtkTextIter begin = *iter;
+
+       gtk_text_iter_forward_char (iter);
+
+       if (gtk_text_iter_ends_line (iter) && !gtk_text_iter_starts_line (iter))
+       {
+               if (gtk_text_iter_is_end (iter))
+                       gtk_text_iter_backward_char (iter);
+               else
+                       gtk_text_iter_forward_char (iter);
+       }
+
+       return !gtk_text_iter_equal (&begin, iter);
 }
 
 static gboolean
 motion_forward_char_same_line (GtkTextIter   *iter,
                                GtkSourceView *view)
 {
-       if (!gtk_text_iter_ends_line (iter))
+       GtkTextIter begin = *iter;
+
+       gtk_text_iter_forward_char (iter);
+
+       if (gtk_text_iter_ends_line (iter) && !gtk_text_iter_starts_line (iter))
        {
-               return gtk_text_iter_forward_char (iter);
+               gtk_text_iter_backward_char (iter);
        }
 
-       return FALSE;
+       return !gtk_text_iter_equal (&begin, iter);
 }
 
 static gboolean
 motion_backward_char (GtkTextIter   *iter,
                       GtkSourceView *view)
 {
-       return gtk_text_iter_backward_char (iter);
+       GtkTextIter begin = *iter;
+
+       if (gtk_text_iter_backward_char (iter))
+       {
+               if (gtk_text_iter_ends_line (iter) && !gtk_text_iter_starts_line (iter))
+               {
+                       gtk_text_iter_backward_char (iter);
+               }
+       }
+
+       return !gtk_text_iter_equal (&begin, iter);
 }
 
 static gboolean


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