[gtksourceview/wip/chergert/vim] use count_set



commit de2fccde382c4c8a0b9cd1c4792c0bd57303ac7f
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 28 14:30:30 2021 -0700

    use count_set

 gtksourceview/vim/gtk-source-vim-motion.c | 18 +++++-------------
 gtksourceview/vim/gtk-source-vim-state.c  | 14 ++++++++++++++
 gtksourceview/vim/gtk-source-vim-state.h  |  1 +
 3 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 8f1c955f..96d69fcf 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -1121,7 +1121,7 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
                g_assert_not_reached ();
        }
 
-       if (count != 0 && get_number (keyval, &n))
+       if (gtk_source_vim_state_get_count_set (state) && get_number (keyval, &n))
        {
                count = count * 10 + n;
                gtk_source_vim_state_set_count (state, count);
@@ -1259,9 +1259,7 @@ static void
 gtk_source_vim_motion_repeat (GtkSourceVimState *state)
 {
        GtkSourceVimMotion *self = (GtkSourceVimMotion *)state;
-       GtkSourceBuffer *buffer;
-       GtkTextIter insert, selection;
-       gboolean has_selection;
+       GtkTextIter iter;
        int count;
 
        g_assert (GTK_SOURCE_IS_VIM_MOTION (self));
@@ -1271,24 +1269,18 @@ gtk_source_vim_motion_repeat (GtkSourceVimState *state)
                return;
        }
 
-       buffer = gtk_source_vim_state_get_buffer (state, &insert, &selection);
-       has_selection = !gtk_text_iter_equal (&insert, &selection);
+       gtk_source_vim_state_get_buffer (state, &iter, NULL);
        count = gtk_source_vim_state_get_count (state);
 
        do
        {
-               if (!gtk_source_vim_motion_apply (self, &insert, FALSE))
+               if (!gtk_source_vim_motion_apply (self, &iter, FALSE))
                {
                        break;
                }
        } while (--count > 0);
 
-       if (has_selection)
-               gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (buffer),
-                                          gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer)),
-                                          &insert);
-       else
-               gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &insert, &insert);
+       gtk_source_vim_state_select (state, &iter, &iter);
 }
 
 static void
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 6ca165f2..72003029 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -32,7 +32,10 @@ typedef struct
        GtkSourceVimState *parent;
        GtkSourceVimState *child;
        GtkSourceView     *view;
+
        int                count;
+
+       guint              count_set : 1;
 } GtkSourceVimStatePrivate;
 
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkSourceVimState, gtk_source_vim_state, G_TYPE_OBJECT)
@@ -784,6 +787,7 @@ gtk_source_vim_state_set_count (GtkSourceVimState *self,
        g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
 
        priv->count = count ? count : 1;
+       priv->count_set = TRUE;
 }
 
 void
@@ -804,3 +808,13 @@ gtk_source_vim_state_set_parent (GtkSourceVimState *self,
                g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PARENT]);
        }
 }
+
+gboolean
+gtk_source_vim_state_get_count_set (GtkSourceVimState *self)
+{
+       GtkSourceVimStatePrivate *priv = gtk_source_vim_state_get_instance_private (self);
+
+       g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), FALSE);
+
+       return priv->count_set;
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 43061a70..d0f591d5 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -74,6 +74,7 @@ GtkSourceBuffer   *gtk_source_vim_state_get_buffer            (GtkSourceVimState
 GtkSourceVimState *gtk_source_vim_state_get_root              (GtkSourceVimState *self);
 GtkSourceVimState *gtk_source_vim_state_get_parent            (GtkSourceVimState *self);
 int                gtk_source_vim_state_get_count             (GtkSourceVimState *self);
+gboolean           gtk_source_vim_state_get_count_set         (GtkSourceVimState *self);
 void               gtk_source_vim_state_set_count             (GtkSourceVimState *self,
                                                                int                count);
 gboolean           gtk_source_vim_state_handle_event          (GtkSourceVimState *self,


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