[gtksourceview/wip/chergert/vim: 195/293] do insert event capture from capture vfunc




commit e5de10f219ab8618615af9631002f701a67983ac
Author: Christian Hergert <chergert redhat com>
Date:   Mon Nov 1 15:18:07 2021 -0700

    do insert event capture from capture vfunc

 gtksourceview/vim/gtk-source-vim-insert.c | 49 ++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index f510a502..38506a64 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -92,29 +92,58 @@ clear_to_first_char (GtkSourceVimInsert *self)
 }
 
 static gboolean
-gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
-                                    GdkEvent          *event)
+gtk_source_vim_insert_capture (GtkSourceVimState *state,
+                               GdkEvent          *event)
 {
        GtkSourceVimInsert *self = (GtkSourceVimInsert *)state;
-       GtkSourceView *view;
+       GtkSourceVimState *child;
        GdkModifierType mods;
        guint keyval;
 
        g_assert (GTK_SOURCE_IS_VIM_INSERT (self));
        g_assert (event != NULL);
 
-       if (!(view = gtk_source_vim_state_get_view (state)))
+       if (self->finished)
+       {
                return FALSE;
+       }
 
+       child = gtk_source_vim_state_get_child (state);
        keyval = gdk_key_event_get_keyval (event);
        mods = gdk_event_get_modifier_state (event)
             & gtk_accelerator_get_default_mod_mask ();
 
-       if (!gtk_source_vim_state_is_escape (keyval, mods))
+       if (child != NULL)
+       {
+               gtk_source_vim_text_history_record (self->history, event);
+       }
+       else if (!gtk_source_vim_state_is_escape (keyval, mods))
        {
                gtk_source_vim_text_history_record (self->history, event);
        }
 
+       return FALSE;
+}
+
+static gboolean
+gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
+                                    GdkEvent          *event)
+{
+       GtkSourceVimInsert *self = (GtkSourceVimInsert *)state;
+       GtkSourceView *view;
+       GdkModifierType mods;
+       guint keyval;
+
+       g_assert (GTK_SOURCE_IS_VIM_INSERT (self));
+       g_assert (event != NULL);
+
+       if (!(view = gtk_source_vim_state_get_view (state)))
+               return FALSE;
+
+       keyval = gdk_key_event_get_keyval (event);
+       mods = gdk_event_get_modifier_state (event)
+            & gtk_accelerator_get_default_mod_mask ();
+
        /* Allow input methods to complete */
        if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event))
                return TRUE;
@@ -158,9 +187,10 @@ gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
                        break;
        }
 
-       /* Because we're in overwrite mode, we need to deliver the
-        * event directly to the textview so that we can avoid
-        * overwriting the content at the current character.
+       /* XXX: Currently we do not use overwrite mode while in insert even
+        * though that is the only way to get a block cursor. To do that we'd
+        * have to be able to commit text to the textview through the input
+        * method and we don't have a way to do that yet.
         */
 
        return FALSE;
@@ -299,6 +329,8 @@ gtk_source_vim_insert_leave (GtkSourceVimState *state)
 
        g_assert (GTK_SOURCE_IS_VIM_INSERT (self));
 
+       self->finished = TRUE;
+
        count = gtk_source_vim_state_get_count (state);
        history = GTK_SOURCE_VIM_STATE (self->history);
 
@@ -421,6 +453,7 @@ gtk_source_vim_insert_class_init (GtkSourceVimInsertClass *klass)
 
        state_class->command_bar_text = _("-- INSERT --");
        state_class->append_command = gtk_source_vim_insert_append_command;
+       state_class->capture = gtk_source_vim_insert_capture;
        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;


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