[gtksourceview/wip/chergert/vim] move begin/end user action to normal mode suspend/resume



commit 0a63aa8075a150e76e3e2dbbc8c147fc61736b82
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 27 16:43:23 2021 -0700

    move begin/end user action to normal mode suspend/resume

 gtksourceview/vim/gtk-source-vim-insert.c  | 13 -------------
 gtksourceview/vim/gtk-source-vim-normal.c  | 17 +++++++++++++++++
 gtksourceview/vim/gtk-source-vim-replace.c | 17 -----------------
 3 files changed, 17 insertions(+), 30 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index 54cee7e3..52e2b4b7 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -190,7 +190,6 @@ gtk_source_vim_insert_enter (GtkSourceVimState *state)
 
        view = gtk_source_vim_state_get_view (state);
        buffer = gtk_source_vim_state_get_buffer (state, &iter, NULL);
-       gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
 
        if (self->suffix)
        {
@@ -221,17 +220,6 @@ gtk_source_vim_insert_enter (GtkSourceVimState *state)
        }
 }
 
-static void
-gtk_source_vim_insert_leave (GtkSourceVimState *state)
-{
-       GtkSourceBuffer *buffer;
-
-       g_assert (GTK_SOURCE_IS_VIM_INSERT (state));
-
-       buffer = gtk_source_vim_state_get_buffer (state, NULL, NULL);
-       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
-}
-
 static void
 gtk_source_vim_insert_append_command (GtkSourceVimState *state,
                                       GString           *string)
@@ -319,7 +307,6 @@ gtk_source_vim_insert_class_init (GtkSourceVimInsertClass *klass)
        state_class->handle_event = gtk_source_vim_insert_handle_event;
        state_class->resume = gtk_source_vim_insert_resume;
        state_class->enter = gtk_source_vim_insert_enter;
-       state_class->leave = gtk_source_vim_insert_leave;
 
        properties [PROP_INDENT] =
                g_param_spec_boolean ("indent",
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 5adf4b43..f34743fe 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -884,6 +884,20 @@ gtk_source_vim_normal_handle_keypress (GtkSourceVimState *state,
        return self->handler (self, keyval, keycode, mods, string);
 }
 
+static void
+gtk_source_vim_normal_suspend (GtkSourceVimState *state,
+                               GtkSourceVimState *to)
+{
+       GtkSourceVimNormal *self = (GtkSourceVimNormal *)state;
+       GtkSourceBuffer *buffer;
+
+       g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+       g_assert (GTK_SOURCE_IS_VIM_STATE (to));
+
+       buffer = gtk_source_vim_state_get_buffer (state, NULL, NULL);
+       gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
+}
+
 static void
 gtk_source_vim_normal_resume (GtkSourceVimState *state,
                               GtkSourceVimState *from)
@@ -905,6 +919,8 @@ gtk_source_vim_normal_resume (GtkSourceVimState *state,
                gtk_source_vim_state_repeat (from, self->repeat - 1);
        }
 
+       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
+
        /* Go back one character if we exited replace/insert state */
        if (GTK_SOURCE_IS_VIM_INSERT (from) || GTK_SOURCE_IS_VIM_REPLACE (from))
                go_backward_char (self);
@@ -964,6 +980,7 @@ gtk_source_vim_normal_class_init (GtkSourceVimNormalClass *klass)
        state_class->handle_keypress = gtk_source_vim_normal_handle_keypress;
        state_class->enter = gtk_source_vim_normal_enter;
        state_class->resume = gtk_source_vim_normal_resume;
+       state_class->suspend = gtk_source_vim_normal_suspend;
 }
 
 static void
diff --git a/gtksourceview/vim/gtk-source-vim-replace.c b/gtksourceview/vim/gtk-source-vim-replace.c
index f825e16a..a284f5fe 100644
--- a/gtksourceview/vim/gtk-source-vim-replace.c
+++ b/gtksourceview/vim/gtk-source-vim-replace.c
@@ -93,25 +93,9 @@ gtk_source_vim_replace_handle_keypress (GtkSourceVimState *state,
 static void
 gtk_source_vim_replace_enter (GtkSourceVimState *state)
 {
-       GtkSourceBuffer *buffer;
-
        g_assert (GTK_SOURCE_IS_VIM_REPLACE (state));
 
        gtk_source_vim_state_set_overwrite (state, TRUE);
-
-       buffer = gtk_source_vim_state_get_buffer (state, NULL, NULL);
-       gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
-}
-
-static void
-gtk_source_vim_replace_leave (GtkSourceVimState *state)
-{
-       GtkSourceBuffer *buffer;
-
-       g_assert (GTK_SOURCE_IS_VIM_REPLACE (state));
-
-       buffer = gtk_source_vim_state_get_buffer (state, NULL, NULL);
-       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
 }
 
 static void
@@ -141,7 +125,6 @@ gtk_source_vim_replace_class_init (GtkSourceVimReplaceClass *klass)
        state_class->append_command = gtk_source_vim_replace_append_command;
        state_class->handle_keypress = gtk_source_vim_replace_handle_keypress;
        state_class->enter = gtk_source_vim_replace_enter;
-       state_class->leave = gtk_source_vim_replace_leave;
        state_class->resume = gtk_source_vim_replace_resume;
 }
 


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