[gtksourceview/wip/chergert/vim] track commands that can repeat



commit 717f6069fad8709d315873fd5e8da4d493dd9b4d
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 29 12:57:49 2021 -0700

    track commands that can repeat

 gtksourceview/vim/gtk-source-vim-command.c |  6 +++--
 gtksourceview/vim/gtk-source-vim-delete.c  |  1 +
 gtksourceview/vim/gtk-source-vim-insert.c  |  1 +
 gtksourceview/vim/gtk-source-vim-replace.c |  1 +
 gtksourceview/vim/gtk-source-vim-state.c   | 35 +++++++++++++++++++-----------
 gtksourceview/vim/gtk-source-vim-state.h   |  5 +++--
 6 files changed, 32 insertions(+), 17 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index 46017c79..89d48872 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -29,10 +29,10 @@ typedef void (*Command) (GtkSourceVimCommand *self);
 
 struct _GtkSourceVimCommand
 {
-       GtkSourceVimState parent_instance;
+       GtkSourceVimState   parent_instance;
        GtkSourceVimMotion *motion;
        GtkSourceVimMotion *selection_motion;
-       char *command;
+       char               *command;
 };
 
 G_DEFINE_TYPE (GtkSourceVimCommand, gtk_source_vim_command, GTK_SOURCE_TYPE_VIM_STATE)
@@ -74,6 +74,8 @@ gtk_source_vim_command_join (GtkSourceVimCommand *self)
        gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &iter, &iter);
 
        gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
+
+       gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
 }
 
 static void
diff --git a/gtksourceview/vim/gtk-source-vim-delete.c b/gtksourceview/vim/gtk-source-vim-delete.c
index a42d7b72..c9f1fde7 100644
--- a/gtksourceview/vim/gtk-source-vim-delete.c
+++ b/gtksourceview/vim/gtk-source-vim-delete.c
@@ -218,4 +218,5 @@ gtk_source_vim_delete_class_init (GtkSourceVimDeleteClass *klass)
 static void
 gtk_source_vim_delete_init (GtkSourceVimDelete *self)
 {
+       gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
 }
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index 0270ab00..f510a502 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -455,6 +455,7 @@ static void
 gtk_source_vim_insert_init (GtkSourceVimInsert *self)
 {
        self->at = GTK_SOURCE_VIM_INSERT_HERE;
+       gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
 }
 
 void
diff --git a/gtksourceview/vim/gtk-source-vim-replace.c b/gtksourceview/vim/gtk-source-vim-replace.c
index 5818a57c..226ccc5a 100644
--- a/gtksourceview/vim/gtk-source-vim-replace.c
+++ b/gtksourceview/vim/gtk-source-vim-replace.c
@@ -133,4 +133,5 @@ gtk_source_vim_replace_class_init (GtkSourceVimReplaceClass *klass)
 static void
 gtk_source_vim_replace_init (GtkSourceVimReplace *self)
 {
+       gtk_source_vim_state_set_can_repeat (GTK_SOURCE_VIM_STATE (self), TRUE);
 }
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 66ae9b8d..4819444a 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -36,6 +36,7 @@ typedef struct
        int                count;
 
        guint              count_set : 1;
+       guint              can_repeat : 1;
 } GtkSourceVimStatePrivate;
 
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkSourceVimState, gtk_source_vim_state, G_TYPE_OBJECT)
@@ -373,19 +374,6 @@ gtk_source_vim_state_repeat (GtkSourceVimState *self)
        }
 }
 
-gboolean
-gtk_source_vim_state_get_can_repeat (GtkSourceVimState *self)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), FALSE);
-
-       if (GTK_SOURCE_VIM_STATE_GET_CLASS (self)->get_can_repeat)
-       {
-               return GTK_SOURCE_VIM_STATE_GET_CLASS (self)->get_can_repeat (self);
-       }
-
-       return FALSE;
-}
-
 gboolean
 gtk_source_vim_state_handle_event (GtkSourceVimState *self,
                                    GdkEvent          *event)
@@ -840,3 +828,24 @@ gtk_source_vim_state_end_user_action (GtkSourceVimState *self)
        buffer = gtk_source_vim_state_get_buffer (self, NULL, NULL);
        gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
 }
+
+gboolean
+gtk_source_vim_state_get_can_repeat (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->can_repeat;
+}
+
+void
+gtk_source_vim_state_set_can_repeat (GtkSourceVimState *self,
+                                     gboolean           can_repeat)
+{
+       GtkSourceVimStatePrivate *priv = gtk_source_vim_state_get_instance_private (self);
+
+       g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
+
+       priv->can_repeat = !!can_repeat;
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index fdfb67d6..2e0aa12b 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -51,7 +51,6 @@ struct _GtkSourceVimStateClass
                                     guint              keycode,
                                     GdkModifierType    mods,
                                     const char        *string);
-       gboolean (*get_can_repeat)  (GtkSourceVimState *state);
        void     (*repeat)          (GtkSourceVimState *state);
        void     (*append_command)  (GtkSourceVimState *state,
                                     GString           *string);
@@ -77,13 +76,15 @@ int                gtk_source_vim_state_get_count             (GtkSourceVimState
 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_get_can_repeat        (GtkSourceVimState *self);
+void               gtk_source_vim_state_set_can_repeat        (GtkSourceVimState *self,
+                                                               gboolean           can_repeat);
 void               gtk_source_vim_state_begin_user_action     (GtkSourceVimState *self);
 void               gtk_source_vim_state_end_user_action       (GtkSourceVimState *self);
 gboolean           gtk_source_vim_state_handle_event          (GtkSourceVimState *self,
                                                                GdkEvent          *event);
 void               gtk_source_vim_state_set_overwrite         (GtkSourceVimState *self,
                                                                gboolean           overwrite);
-gboolean           gtk_source_vim_state_get_can_repeat        (GtkSourceVimState *self);
 gboolean           gtk_source_vim_state_synthesize            (GtkSourceVimState *self,
                                                                guint              keyval,
                                                                GdkModifierType    mods);


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