[gtksourceview/wip/chergert/vim] few more tweaks on accels and overwrite



commit eb8ea502e24c8e912221d86fae5d3bb0b0522c9c
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 22 09:37:11 2021 -0700

    few more tweaks on accels and overwrite

 gtksourceview/gtksourcevimimcontext.c     | 41 ++++++-------------------------
 gtksourceview/vim/gtk-source-vim-insert.c |  6 ++++-
 gtksourceview/vim/gtk-source-vim-normal.c |  1 +
 gtksourceview/vim/gtk-source-vim-state.c  | 19 ++++++++------
 4 files changed, 26 insertions(+), 41 deletions(-)
---
diff --git a/gtksourceview/gtksourcevimimcontext.c b/gtksourceview/gtksourcevimimcontext.c
index c61aec94..d2164e9a 100644
--- a/gtksourceview/gtksourcevimimcontext.c
+++ b/gtksourceview/gtksourcevimimcontext.c
@@ -59,7 +59,10 @@ gtk_source_vim_im_context_set_client_widget (GtkIMContext *context,
        g_return_if_fail (GTK_SOURCE_IS_VIM_IM_CONTEXT (self));
 
        if (!GTK_SOURCE_IS_VIEW (widget))
+       {
+               gtk_text_view_set_overwrite (GTK_TEXT_VIEW (widget), FALSE);
                return;
+       }
 
        if (self->vim != NULL)
        {
@@ -67,6 +70,9 @@ gtk_source_vim_im_context_set_client_widget (GtkIMContext *context,
                g_clear_object (&self->vim);
        }
 
+       /* Emulate block cursor with "overwrite" */
+       gtk_text_view_set_overwrite (GTK_TEXT_VIEW (widget), TRUE);
+
        self->vim = gtk_source_vim_new (GTK_SOURCE_VIEW (widget));
 
        g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COMMAND_TEXT]);
@@ -86,45 +92,14 @@ gtk_source_vim_im_context_reset (GtkIMContext *context)
 static void
 gtk_source_vim_im_context_focus_in (GtkIMContext *context)
 {
-       GtkSourceVimIMContext *self = (GtkSourceVimIMContext *)context;
-       GtkSourceView *view;
-
-       g_return_if_fail (GTK_SOURCE_IS_VIM_IM_CONTEXT (self));
-
-       if (self->vim == NULL)
-               return;
-
-       view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (self->vim));
-
-       if (view != NULL)
-       {
-               gtk_text_view_set_overwrite (GTK_TEXT_VIEW (view), TRUE);
-               gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), TRUE);
-       }
+       g_assert (GTK_SOURCE_IS_VIM_IM_CONTEXT (context));
 
-       g_print ("Focus in %p\n", view);
 }
 
 static void
 gtk_source_vim_im_context_focus_out (GtkIMContext *context)
 {
-       GtkSourceVimIMContext *self = (GtkSourceVimIMContext *)context;
-       GtkSourceView *view;
-
-       g_return_if_fail (GTK_SOURCE_IS_VIM_IM_CONTEXT (self));
-
-       g_print ("Focus out\n");
-
-       if (self->vim == NULL)
-               return;
-
-       view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (self->vim));
-
-       if (view != NULL)
-       {
-               gtk_text_view_set_overwrite (GTK_TEXT_VIEW (view), FALSE);
-               gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
-       }
+       g_assert (GTK_SOURCE_IS_VIM_IM_CONTEXT (context));
 }
 
 static gboolean
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index 6b83748f..4643b0d0 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -105,6 +105,7 @@ gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
                {
                        case GDK_KEY_Return:
                        case GDK_KEY_KP_Enter:
+                       case GDK_KEY_ISO_Enter:
                                return gtk_source_vim_insert_literal (self, "\n");
 
                        case GDK_KEY_BackSpace:
@@ -169,7 +170,10 @@ gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
                }
        }
 
-       /* Pass-through to the next controller */
+       /* 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.
+        */
 
        return FALSE;
 }
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index ec6a1b91..e3471fca 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -361,6 +361,7 @@ key_handler_initial (GtkSourceVimNormal *self,
                        case GDK_KEY_G:
                        case GDK_KEY_h:
                        case GDK_KEY_H:
+                       case GDK_KEY_ISO_Enter:
                        case GDK_KEY_j:
                        case GDK_KEY_k:
                        case GDK_KEY_KP_Enter:
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 8b3561fa..43e4761c 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -69,18 +69,22 @@ keyval_to_string (guint           keyval,
 
                case GDK_KEY_Return:
                case GDK_KEY_KP_Enter:
+               case GDK_KEY_ISO_Enter:
                        str[pos++] = '\n';
                        break;
 
-               case GDK_KEY_Control_R:
-               case GDK_KEY_Control_L:
-                       pos = 0;
-                       break;
-
                default:
                {
-                       gunichar ch = gdk_keyval_to_unicode (keyval);
+                       gunichar ch;
+
+                       /* ctrl things like ^M ^L are all uppercase */
+                       if ((mods & GDK_CONTROL_MASK) != 0)
+                               ch = gdk_keyval_to_unicode (gdk_keyval_to_upper (keyval));
+                       else
+                               ch = gdk_keyval_to_unicode (keyval);
+
                        pos += g_unichar_to_utf8 (ch, &str[pos]);
+
                        break;
                }
        }
@@ -109,7 +113,8 @@ gtk_source_vim_state_real_handle_event (GtkSourceVimState *self,
 
                keyval = gdk_key_event_get_keyval (event);
                keycode = gdk_key_event_get_keycode (event);
-               mods = gdk_key_event_get_consumed_modifiers (event);
+               mods = gdk_key_event_get_consumed_modifiers (event)
+                    & gtk_accelerator_get_default_mod_mask ();
                keyval_to_string (keyval, mods, string);
 
                return GTK_SOURCE_VIM_STATE_GET_CLASS (self)->handle_keypress (self, keyval, keycode, mods, 
string);


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