[gtksourceview/wip/chergert/vim: 342/363] add nN and reverse them based on # or *




commit f2d56a1bd31001eb274dd87c992ff5890cc060ad
Author: Christian Hergert <chergert redhat com>
Date:   Sat Nov 6 19:46:33 2021 -0700

    add nN and reverse them based on # or *

 gtksourceview/vim/gtk-source-vim-motion.c | 61 +++++++++++++++++++++++--------
 1 file changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index c278b613..391784a9 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -107,9 +107,6 @@ struct _GtkSourceVimMotion
         * as paragraph or sentence movements.
         */
        MotionWise wise : 1;
-
-       /* If search is reversed (flips n vs N) */
-       guint reverse_search : 1;
 };
 
 G_DEFINE_TYPE (GtkSourceVimMotion, gtk_source_vim_motion, GTK_SOURCE_TYPE_VIM_STATE)
@@ -1295,10 +1292,10 @@ WORD_under_cursor (const GtkTextIter *iter)
 }
 
 static gboolean
-motion_forward_search (GtkTextIter        *iter,
-                       GtkSourceVimMotion *self,
-                       gboolean            WORD,
-                       gboolean            reverse)
+motion_search (GtkTextIter        *iter,
+               GtkSourceVimMotion *self,
+               gboolean            WORD,
+               gboolean            reverse)
 {
        GtkSourceSearchContext *context;
        GtkSourceSearchSettings *settings;
@@ -1316,9 +1313,8 @@ motion_forward_search (GtkTextIter        *iter,
                return FALSE;
        }
 
-       self->reverse_search = !!reverse;
-
        gtk_source_vim_state_get_search (GTK_SOURCE_VIM_STATE (self), &settings, &context);
+       gtk_source_vim_state_set_reverse_search (GTK_SOURCE_VIM_STATE (self), reverse);
 
        if (!gtk_source_search_settings_get_at_word_boundaries (settings))
        {
@@ -1364,24 +1360,47 @@ static gboolean
 motion_forward_search_word (GtkTextIter        *iter,
                             GtkSourceVimMotion *self)
 {
-       return motion_forward_search (iter, self, FALSE, FALSE);
+       return motion_search (iter, self, FALSE, FALSE);
 }
 
 static gboolean
 motion_backward_search_word (GtkTextIter        *iter,
                              GtkSourceVimMotion *self)
 {
-       return motion_forward_search (iter, self, FALSE, TRUE);
+       return motion_search (iter, self, FALSE, TRUE);
 }
 
-#if 0
 static gboolean
-motion_forward_search_WORD (GtkTextIter        *iter,
-                            GtkSourceVimMotion *self)
+motion_next_search (GtkTextIter        *iter,
+                    GtkSourceVimMotion *self)
 {
-       return motion_forward_search (iter, self, TRUE, FALSE);
+       GtkSourceSearchContext *context;
+       gboolean has_wrapped_around;
+       gboolean matched;
+
+       gtk_source_vim_state_get_search (GTK_SOURCE_VIM_STATE (self), NULL, &context);
+
+       gtk_text_iter_forward_char (iter);
+
+       matched = gtk_source_search_context_forward (context, iter, iter, NULL, &has_wrapped_around);
+
+       return matched;
+}
+
+static gboolean
+motion_prev_search (GtkTextIter        *iter,
+                    GtkSourceVimMotion *self)
+{
+       GtkSourceSearchContext *context;
+       gboolean has_wrapped_around;
+       gboolean matched;
+
+       gtk_source_vim_state_get_search (GTK_SOURCE_VIM_STATE (self), NULL, &context);
+
+        matched = gtk_source_search_context_backward (context, iter, iter, NULL, &has_wrapped_around);
+
+       return matched;
 }
-#endif
 
 GtkSourceVimState *
 gtk_source_vim_motion_new (void)
@@ -1661,7 +1680,17 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
                        return gtk_source_vim_motion_complete (self, motion_backward_search_word, INCLUSIVE, 
CHARWISE);
 
                case GDK_KEY_n:
+                       if (gtk_source_vim_state_get_reverse_search (GTK_SOURCE_VIM_STATE (self)))
+                               return gtk_source_vim_motion_complete (self, motion_prev_search, INCLUSIVE, 
CHARWISE);
+                       else
+                               return gtk_source_vim_motion_complete (self, motion_next_search, INCLUSIVE, 
CHARWISE);
+
                case GDK_KEY_N:
+                       if (gtk_source_vim_state_get_reverse_search (GTK_SOURCE_VIM_STATE (self)))
+                               return gtk_source_vim_motion_complete (self, motion_next_search, INCLUSIVE, 
CHARWISE);
+                       else
+                               return gtk_source_vim_motion_complete (self, motion_prev_search, INCLUSIVE, 
CHARWISE);
+
                case GDK_KEY_percent:
                        /* exclusive */
                        /* charwise */


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