[gtksourceview/wip/chergert/vim: 301/363] allow attaching a text object to insert mode to delete it




commit b96db003bdec2eb4a80415a63ca26d9c319437f9
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 5 00:07:31 2021 -0700

    allow attaching a text object to insert mode to delete it

 gtksourceview/vim/gtk-source-vim-insert.c | 67 ++++++++++++++++++++-----------
 gtksourceview/vim/gtk-source-vim-insert.h | 27 +++++++------
 2 files changed, 58 insertions(+), 36 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index 1a52dc6a..0bd8e870 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -37,6 +37,7 @@ struct _GtkSourceVimInsert
        GtkSourceVimTextHistory *history;
        GtkSourceVimMotion      *motion;
        GtkSourceVimMotion      *selection_motion;
+       GtkSourceVimTextObject  *text_object;
        char                    *prefix;
        char                    *suffix;
        GtkSourceVimInsertAt     at;
@@ -204,41 +205,49 @@ gtk_source_vim_insert_prepare (GtkSourceVimInsert *self)
        view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (self));
        buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
 
-       if (self->motion)
+       if (self->text_object)
        {
-               gtk_source_vim_motion_apply (self->motion, &iter, TRUE);
-
-               if (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR ||
-                   self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF)
+               selection = iter;
+               gtk_source_vim_text_object_select (self->text_object, &iter, &selection);
+       }
+       else
+       {
+               if (self->motion)
                {
+                       gtk_source_vim_motion_apply (self->motion, &iter, TRUE);
+
                        if (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR ||
-                           (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF && 
!gtk_text_iter_is_start (&iter)) ||
-                           (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_SOL && 
!gtk_text_iter_starts_line (&iter)))
+                           self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF)
                        {
-                               if (!gtk_text_iter_ends_line (&iter))
-                                       gtk_text_iter_forward_char (&iter);
+                               if (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR ||
+                                   (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF && 
!gtk_text_iter_is_start (&iter)) ||
+                                   (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_SOL && 
!gtk_text_iter_starts_line (&iter)))
+                               {
+                                       if (!gtk_text_iter_ends_line (&iter))
+                                               gtk_text_iter_forward_char (&iter);
+                               }
                        }
-               }
 
-               if (self->selection_motion == NULL)
-               {
-                       selection = iter;
+                       if (self->selection_motion == NULL)
+                       {
+                               selection = iter;
+                       }
                }
-       }
 
-       if (self->selection_motion)
-       {
-               gtk_source_vim_motion_apply (self->selection_motion, &selection, TRUE);
-
-               if (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR ||
-                   self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF)
+               if (self->selection_motion)
                {
+                       gtk_source_vim_motion_apply (self->selection_motion, &selection, TRUE);
+
                        if (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR ||
-                           (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF && 
!gtk_text_iter_is_start (&iter)) ||
-                           (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_SOL && 
!gtk_text_iter_starts_line (&iter)))
+                           self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF)
                        {
-                               if (!gtk_text_iter_ends_line (&selection))
-                                       gtk_text_iter_forward_char (&selection);
+                               if (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR ||
+                                   (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_BOF && 
!gtk_text_iter_is_start (&iter)) ||
+                                   (self->at == GTK_SOURCE_VIM_INSERT_AFTER_CHAR_UNLESS_SOL && 
!gtk_text_iter_starts_line (&iter)))
+                               {
+                                       if (!gtk_text_iter_ends_line (&selection))
+                                               gtk_text_iter_forward_char (&selection);
+                               }
                        }
                }
        }
@@ -415,6 +424,7 @@ gtk_source_vim_insert_dispose (GObject *object)
        g_clear_object (&self->history);
        g_clear_object (&self->motion);
        g_clear_object (&self->selection_motion);
+       g_clear_object (&self->text_object);
 
        G_OBJECT_CLASS (gtk_source_vim_insert_parent_class)->dispose (object);
 }
@@ -540,3 +550,12 @@ gtk_source_vim_insert_set_at (GtkSourceVimInsert   *self,
 
        self->at = at;
 }
+
+void
+gtk_source_vim_insert_set_text_object (GtkSourceVimInsert     *self,
+                                       GtkSourceVimTextObject *text_object)
+{
+       g_return_if_fail (GTK_SOURCE_IS_VIM_INSERT (self));
+
+       g_set_object (&self->text_object, text_object);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-insert.h b/gtksourceview/vim/gtk-source-vim-insert.h
index 6582b54c..6d8cf891 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.h
+++ b/gtksourceview/vim/gtk-source-vim-insert.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
 
@@ -40,18 +41,20 @@ typedef enum
 G_DECLARE_FINAL_TYPE (GtkSourceVimInsert, gtk_source_vim_insert, GTK_SOURCE, VIM_INSERT, GtkSourceVimState)
 
 GtkSourceVimState *gtk_source_vim_insert_new                  (void);
-void               gtk_source_vim_insert_set_at               (GtkSourceVimInsert   *self,
-                                                               GtkSourceVimInsertAt  at);
-void               gtk_source_vim_insert_set_motion           (GtkSourceVimInsert   *self,
-                                                               GtkSourceVimMotion   *motion);
-void               gtk_source_vim_insert_set_selection_motion (GtkSourceVimInsert   *self,
-                                                               GtkSourceVimMotion   *selection_motion);
-void               gtk_source_vim_insert_set_indent           (GtkSourceVimInsert   *self,
-                                                               gboolean              indent);
-void               gtk_source_vim_insert_set_prefix           (GtkSourceVimInsert   *self,
-                                                               const char           *prefix);
-void               gtk_source_vim_insert_set_suffix           (GtkSourceVimInsert   *self,
-                                                               const char           *suffix);
+void               gtk_source_vim_insert_set_at               (GtkSourceVimInsert     *self,
+                                                               GtkSourceVimInsertAt    at);
+void               gtk_source_vim_insert_set_motion           (GtkSourceVimInsert     *self,
+                                                               GtkSourceVimMotion     *motion);
+void               gtk_source_vim_insert_set_selection_motion (GtkSourceVimInsert     *self,
+                                                               GtkSourceVimMotion     *selection_motion);
+void               gtk_source_vim_insert_set_text_object      (GtkSourceVimInsert     *self,
+                                                               GtkSourceVimTextObject *text_object);
+void               gtk_source_vim_insert_set_indent           (GtkSourceVimInsert     *self,
+                                                               gboolean                indent);
+void               gtk_source_vim_insert_set_prefix           (GtkSourceVimInsert     *self,
+                                                               const char             *prefix);
+void               gtk_source_vim_insert_set_suffix           (GtkSourceVimInsert     *self,
+                                                               const char             *suffix);
 
 
 G_END_DECLS


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