[gtksourceview/wip/chergert/vim] make command + motion easier to do going forward



commit 028e910c3e93e2abb9a4547d4270d6118038abfb
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 2 15:31:03 2021 -0700

    make command + motion easier to do going forward

 gtksourceview/vim/gtk-source-vim-normal.c | 51 ++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 21 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index d50094ea..42d0512b 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -232,6 +232,35 @@ gtk_source_vim_normal_begin_command (GtkSourceVimNormal *self,
        gtk_source_vim_state_pop (GTK_SOURCE_VIM_STATE (command));
 }
 
+static gboolean
+gtk_source_vim_normal_begin_command_requiring_motion (GtkSourceVimNormal *self,
+                                                      const char         *command_str)
+{
+       GtkSourceVimState *command;
+       GtkSourceVimState *motion;
+       GtkSourceVimState *selection_motion;
+
+       g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+       g_assert (command_str != NULL);
+
+       motion = gtk_source_vim_motion_new ();
+       selection_motion = gtk_source_vim_motion_new_none ();
+
+       gtk_source_vim_motion_set_apply_on_leave (GTK_SOURCE_VIM_MOTION (motion), FALSE);
+
+       command = g_object_new (GTK_SOURCE_TYPE_VIM_COMMAND,
+                               "selection-motion", selection_motion,
+                               "command", command_str,
+                               NULL);
+
+       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), command);
+       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (command), motion);
+
+       g_clear_object (&selection_motion);
+
+       return TRUE;
+}
+
 static void
 gtk_source_vim_normal_begin_visual (GtkSourceVimNormal     *self,
                                     GtkSourceVimVisualMode  mode)
@@ -745,27 +774,7 @@ key_handler_g (GtkSourceVimNormal *self,
        switch (keyval)
        {
                case GDK_KEY_question:
-               {
-                       GtkSourceVimState *motion;
-                       GtkSourceVimState *selection_motion;
-
-                       new_state = gtk_source_vim_command_new ("rot13");
-                       motion = gtk_source_vim_motion_new ();
-                       selection_motion = gtk_source_vim_motion_new_none ();
-
-                       gtk_source_vim_motion_set_apply_on_leave (GTK_SOURCE_VIM_MOTION (motion), FALSE);
-                       gtk_source_vim_command_set_selection_motion (GTK_SOURCE_VIM_COMMAND (new_state),
-                                                                    GTK_SOURCE_VIM_MOTION 
(selection_motion));
-
-                       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), new_state);
-                       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (new_state), motion);
-
-                       g_assert (gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (self)) == motion);
-
-                       g_object_unref (selection_motion);
-
-                       return TRUE;
-               }
+                       return gtk_source_vim_normal_begin_command_requiring_motion (self, "rot13");
 
                case GDK_KEY_g:
                case GDK_KEY_e:


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