[gtksourceview/wip/chergert/vim: 50/73] add e and E motion




commit 0ecaea0526bc445256df289e4a321f77699c7b80
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 23 10:38:34 2021 -0700

    add e and E motion

 gtksourceview/vim/gtk-source-vim-motion.c | 64 +++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 6a294d29..31040eff 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -130,6 +130,52 @@ forward_classified_start (GtkTextIter  *iter,
        return FALSE;
 }
 
+static gboolean
+forward_classified_end (GtkTextIter  *iter,
+                        gint        (*classify) (gunichar))
+{
+       gunichar ch;
+       gint begin_class;
+       gint cur_class;
+
+       g_assert (iter);
+
+       if (!gtk_text_iter_forward_char (iter))
+               return FALSE;
+
+       /* If we are on space, walk to the start of the next word. */
+       ch = gtk_text_iter_get_char (iter);
+       if (classify (ch) == CLASS_SPACE)
+               if (!forward_classified_start (iter, classify))
+                       return FALSE;
+
+       ch = gtk_text_iter_get_char (iter);
+       begin_class = classify (ch);
+
+       if (begin_class == CLASS_NEWLINE)
+       {
+               gtk_text_iter_backward_char (iter);
+               return TRUE;
+       }
+
+       for (;;)
+       {
+               if (!gtk_text_iter_forward_char (iter))
+                       return FALSE;
+
+               ch = gtk_text_iter_get_char (iter);
+               cur_class = classify (ch);
+
+               if (cur_class != begin_class || cur_class == CLASS_NEWLINE)
+               {
+                       gtk_text_iter_backward_char (iter);
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
 static gboolean
 backward_classified_end (GtkTextIter  *iter,
                          gint        (*classify) (gunichar))
@@ -472,6 +518,20 @@ motion_forward_WORD_start (GtkTextIter   *iter,
        return forward_classified_start (iter, classify_WORD);
 }
 
+static gboolean
+motion_forward_word_end (GtkTextIter   *iter,
+                         GtkSourceView *view)
+{
+       return forward_classified_end (iter, classify_word);
+}
+
+static gboolean
+motion_forward_WORD_end (GtkTextIter   *iter,
+                         GtkSourceView *view)
+{
+       return forward_classified_end (iter, classify_WORD);
+}
+
 static gboolean
 motion_backward_word_start (GtkTextIter   *iter,
                           GtkSourceView *view)
@@ -631,7 +691,11 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
                        return gtk_source_vim_motion_complete (self, motion_backward_WORD_start);
 
                case GDK_KEY_e:
+                       return gtk_source_vim_motion_complete (self, motion_forward_word_end);
+
                case GDK_KEY_E:
+                       return gtk_source_vim_motion_complete (self, motion_forward_WORD_end);
+
                case GDK_KEY_f:
                case GDK_KEY_F:
                case GDK_KEY_n:


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