[gtksourceview/wip/chergert/vim] allow setting text objects on commands



commit 3650c2f32635ac24344af19f7be59652b24f5892
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 5 00:23:28 2021 -0700

    allow setting text objects on commands

 gtksourceview/vim/gtk-source-vim-command.c | 45 +++++++++++++++++++++---------
 gtksourceview/vim/gtk-source-vim-command.h | 15 ++++++----
 2 files changed, 41 insertions(+), 19 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index 592fb818..3e1bdb31 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -35,14 +35,15 @@ typedef void (*Command) (GtkSourceVimCommand *self);
 
 struct _GtkSourceVimCommand
 {
-       GtkSourceVimState   parent_instance;
+       GtkSourceVimState       parent_instance;
 
-       GtkSourceVimMotion *motion;
-       GtkSourceVimMotion *selection_motion;
-       char               *command;
-       char                char_pending[16];
+       GtkSourceVimMotion     *motion;
+       GtkSourceVimMotion     *selection_motion;
+       GtkSourceVimTextObject *text_object;
+       char                   *command;
+       char                    char_pending[16];
 
-       guint               ignore_mark : 1;
+       guint                   ignore_mark : 1;
 };
 
 G_DEFINE_TYPE (GtkSourceVimCommand, gtk_source_vim_command, GTK_SOURCE_TYPE_VIM_STATE)
@@ -571,16 +572,24 @@ gtk_source_vim_command_repeat (GtkSourceVimState *state)
        buffer = gtk_source_vim_state_get_buffer (state, &iter, &selection);
        mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (buffer), NULL, &iter, TRUE);
 
-       if (self->motion)
+       if (self->text_object)
        {
-               gtk_source_vim_motion_apply (self->motion, &iter, TRUE);
-               linewise |= gtk_source_vim_motion_is_linewise (self->motion);
+               selection = iter;
+               gtk_source_vim_text_object_select (self->text_object, &iter, &selection);
        }
-
-       if (self->selection_motion)
+       else
        {
-               gtk_source_vim_motion_apply (self->selection_motion, &selection, TRUE);
-               linewise |= gtk_source_vim_motion_is_linewise (self->selection_motion);
+               if (self->motion)
+               {
+                       gtk_source_vim_motion_apply (self->motion, &iter, TRUE);
+                       linewise |= gtk_source_vim_motion_is_linewise (self->motion);
+               }
+
+               if (self->selection_motion)
+               {
+                       gtk_source_vim_motion_apply (self->selection_motion, &selection, TRUE);
+                       linewise |= gtk_source_vim_motion_is_linewise (self->selection_motion);
+               }
        }
 
        if (linewise)
@@ -658,6 +667,7 @@ gtk_source_vim_command_dispose (GObject *object)
 
        g_clear_object (&self->motion);
        g_clear_object (&self->selection_motion);
+       g_clear_object (&self->text_object);
        g_clear_pointer (&self->command, g_free);
 
        G_OBJECT_CLASS (gtk_source_vim_command_parent_class)->dispose (object);
@@ -841,3 +851,12 @@ gtk_source_vim_command_new (const char *command)
                             "command", command,
                             NULL);
 }
+
+void
+gtk_source_vim_command_set_text_object (GtkSourceVimCommand    *self,
+                                        GtkSourceVimTextObject *text_object)
+{
+       g_return_if_fail (GTK_SOURCE_IS_VIM_COMMAND (self));
+
+       g_set_object (&self->text_object, text_object);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-command.h b/gtksourceview/vim/gtk-source-vim-command.h
index 7bfb2e98..ee03e802 100644
--- a/gtksourceview/vim/gtk-source-vim-command.h
+++ b/gtksourceview/vim/gtk-source-vim-command.h
@@ -23,6 +23,7 @@
 
 #include "gtk-source-vim-motion.h"
 #include "gtk-source-vim-state.h"
+#include "gtk-source-vim-text-object.h"
 
 G_BEGIN_DECLS
 
@@ -30,11 +31,13 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GtkSourceVimCommand, gtk_source_vim_command, GTK_SOURCE, VIM_COMMAND, 
GtkSourceVimState)
 
-GtkSourceVimState *gtk_source_vim_command_new                  (const char          *command);
-const char        *gtk_source_vim_command_get_command          (GtkSourceVimCommand *self);
-void               gtk_source_vim_command_set_motion           (GtkSourceVimCommand *self,
-                                                                GtkSourceVimMotion  *motion);
-void               gtk_source_vim_command_set_selection_motion (GtkSourceVimCommand *self,
-                                                                GtkSourceVimMotion  *selection_motion);
+GtkSourceVimState *gtk_source_vim_command_new                  (const char             *command);
+const char        *gtk_source_vim_command_get_command          (GtkSourceVimCommand    *self);
+void               gtk_source_vim_command_set_motion           (GtkSourceVimCommand    *self,
+                                                                GtkSourceVimMotion     *motion);
+void               gtk_source_vim_command_set_selection_motion (GtkSourceVimCommand    *self,
+                                                                GtkSourceVimMotion     *selection_motion);
+void               gtk_source_vim_command_set_text_object      (GtkSourceVimCommand    *self,
+                                                                GtkSourceVimTextObject *text_objet);
 
 G_END_DECLS


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