[gtksourceview/wip/chergert/vim] work on changes, wrt to numbers like 3S



commit d1963281aa24cdeac792200966839c9319ec0430
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 28 14:18:06 2021 -0700

    work on changes, wrt to numbers like 3S

 gtksourceview/vim/gtk-source-vim-normal.c | 59 ++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 25 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 71b6dd6e..f797bda5 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -209,47 +209,48 @@ gtk_source_vim_normal_begin_delete (GtkSourceVimNormal *self,
 G_GNUC_NULL_TERMINATED
 static GtkSourceVimState *
 gtk_source_vim_normal_begin_change (GtkSourceVimNormal *self,
-                                    GtkSourceVimState  *motion,
+                                    GtkSourceVimState  *insert_motion,
+                                    GtkSourceVimState  *selection_motion,
                                     ...)
 {
        GtkSourceVimState *ret;
-       GtkSourceBuffer *buffer;
        const char *first_property_name;
-       GtkTextIter iter, selection;
        va_list args;
        int count;
 
        g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
-       g_assert (!motion || GTK_SOURCE_IS_VIM_MOTION (motion));
+       g_assert (!insert_motion || GTK_SOURCE_IS_VIM_MOTION (insert_motion));
+       g_assert (!selection_motion || GTK_SOURCE_IS_VIM_MOTION (selection_motion));
 
-       buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
-       count = self->count;
+       count = self->count, self->count = 0;
 
-       gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
+       va_start (args, selection_motion);
+       first_property_name = va_arg (args, const char *);
+       ret = GTK_SOURCE_VIM_STATE (g_object_new_valist (GTK_SOURCE_TYPE_VIM_INSERT, first_property_name, 
args));
+       va_end (args);
 
-       if (motion != NULL)
+       if (insert_motion != NULL)
        {
-               /* Just to attach it to the state machine */
-               gtk_source_vim_motion_set_apply_on_leave (GTK_SOURCE_VIM_MOTION (motion), FALSE);
-               gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), motion);
-               gtk_source_vim_state_pop (g_object_ref (motion));
-
-               /* Apply it to our selection bound */
-               gtk_source_vim_motion_apply (GTK_SOURCE_VIM_MOTION (motion), &iter, TRUE);
-               gtk_text_buffer_delete (GTK_TEXT_BUFFER (buffer), &iter, &selection);
-               gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &iter, &iter);
+               gtk_source_vim_state_set_count (insert_motion, count);
+               gtk_source_vim_motion_set_apply_on_leave (GTK_SOURCE_VIM_MOTION (insert_motion), FALSE);
+               gtk_source_vim_state_set_parent (insert_motion, ret);
+               gtk_source_vim_insert_set_motion (GTK_SOURCE_VIM_INSERT (ret),
+                                                 GTK_SOURCE_VIM_MOTION (insert_motion));
+               g_object_unref (insert_motion);
        }
 
-       va_start (args, motion);
-       first_property_name = va_arg (args, const char *);
-       ret = GTK_SOURCE_VIM_STATE (g_object_new_valist (GTK_SOURCE_TYPE_VIM_INSERT, first_property_name, 
args));
-       va_end (args);
+       if (selection_motion != NULL)
+       {
+               gtk_source_vim_state_set_count (selection_motion, count);
+               gtk_source_vim_motion_set_apply_on_leave (GTK_SOURCE_VIM_MOTION (selection_motion), FALSE);
+               gtk_source_vim_state_set_parent (selection_motion, ret);
+               gtk_source_vim_insert_set_selection_motion (GTK_SOURCE_VIM_INSERT (ret),
+                                                           GTK_SOURCE_VIM_MOTION (selection_motion));
+               g_object_unref (selection_motion);
+       }
 
-       gtk_source_vim_state_set_count (ret, count);
        gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), ret);
 
-       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
-
        return ret;
 }
 
@@ -359,6 +360,7 @@ key_handler_command (GtkSourceVimNormal *self,
                                return gtk_source_vim_normal_bail (self);
                        gtk_source_vim_normal_begin_change (self,
                                                            gtk_source_vim_motion_new_line_end (),
+                                                           gtk_source_vim_motion_new_none (),
                                                            GTK_SOURCE_VIM_INSERT_HERE,
                                                            NULL);
                        return TRUE;
@@ -377,13 +379,20 @@ key_handler_command (GtkSourceVimNormal *self,
                                                            NULL);
                        return TRUE;
 
+               case GDK_KEY_S:
+                       gtk_source_vim_normal_begin_change (self,
+                                                           gtk_source_vim_motion_new_line_end_with_nl (),
+                                                           gtk_source_vim_motion_new_line_start (),
+                                                           GTK_SOURCE_VIM_INSERT_HERE,
+                                                           NULL);
+                       return TRUE;
+
                case GDK_KEY_asciitilde:
                case GDK_KEY_J:
                case GDK_KEY_p:
                case GDK_KEY_P:
                case GDK_KEY_period:
                case GDK_KEY_s:
-               case GDK_KEY_S:
                case GDK_KEY_equal:
                case GDK_KEY_plus:
                        break;


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