[gtksourceview/wip/chergert/vim] share code for keyval to string



commit 2fe0f164bd5ac06b41ba524845741160c8fdb4f6
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 28 14:16:57 2021 -0700

    share code for keyval to string

 gtksourceview/gtksourcevimimcontext.c    | 53 +-------------------------------
 gtksourceview/vim/gtk-source-vim-state.c | 18 +++++++----
 gtksourceview/vim/gtk-source-vim-state.h |  3 ++
 3 files changed, 16 insertions(+), 58 deletions(-)
---
diff --git a/gtksourceview/gtksourcevimimcontext.c b/gtksourceview/gtksourcevimimcontext.c
index 94b9539b..8010fdfe 100644
--- a/gtksourceview/gtksourcevimimcontext.c
+++ b/gtksourceview/gtksourcevimimcontext.c
@@ -52,57 +52,6 @@ enum {
 static GParamSpec *properties[N_PROPS];
 static guint signals[N_SIGNALS];
 
-static inline void
-keyval_to_string (guint           keyval,
-                  GdkModifierType mods,
-                  char            str[16])
-{
-       int pos = 0;
-
-       if (keyval && (mods & GDK_CONTROL_MASK) != 0)
-       {
-               str[pos++] = '^';
-       }
-
-       switch (keyval)
-       {
-               case GDK_KEY_Escape:
-                       str[pos++] = '^';
-                       str[pos++] = '[';
-                       break;
-
-               case GDK_KEY_ISO_Left_Tab:
-               case GDK_KEY_Tab:
-                       str[pos++] = '\\';
-                       str[pos++] = 't';
-                       break;
-
-               case GDK_KEY_Return:
-               case GDK_KEY_KP_Enter:
-               case GDK_KEY_ISO_Enter:
-                       str[pos++] = '\\';
-                       str[pos++] = 'n';
-                       break;
-
-               default:
-               {
-                       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;
-               }
-       }
-
-       str[pos] = 0;
-}
-
 GtkIMContext *
 gtk_source_vim_im_context_new (void)
 {
@@ -236,7 +185,7 @@ gtk_source_vim_im_context_filter_keypress (GtkIMContext *context,
 
                mods = gdk_event_get_modifier_state (event);
                keyval = gdk_key_event_get_keyval (event);
-               keyval_to_string (keyval, mods, str);
+               gtk_source_vim_state_keyval_to_string (keyval, mods, str);
 
                g_signal_emit (self, signals[OBSERVE_KEY], 0, str, self->reset_observer);
 
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 367af5ef..c41a238b 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -46,10 +46,10 @@ enum {
 
 static GParamSpec *properties [N_PROPS];
 
-static inline void
-keyval_to_string (guint           keyval,
-                  GdkModifierType mods,
-                  char            str[16])
+void
+gtk_source_vim_state_keyval_to_string (guint           keyval,
+                                      GdkModifierType mods,
+                                      char            str[16])
 {
        int pos = 0;
 
@@ -65,6 +65,11 @@ keyval_to_string (guint           keyval,
                        str[pos++] = '[';
                        break;
 
+               case GDK_KEY_BackSpace:
+                       str[pos++] = '^';
+                       str[pos++] = 'H';
+                       break;
+
                case GDK_KEY_ISO_Left_Tab:
                case GDK_KEY_Tab:
                        str[pos++] = '\\';
@@ -120,7 +125,7 @@ gtk_source_vim_state_real_handle_event (GtkSourceVimState *self,
                keycode = gdk_key_event_get_keycode (event);
                mods = gdk_event_get_modifier_state (event)
                     & gtk_accelerator_get_default_mod_mask ();
-               keyval_to_string (keyval, mods, string);
+               gtk_source_vim_state_keyval_to_string (keyval, mods, string);
 
                return GTK_SOURCE_VIM_STATE_GET_CLASS (self)->handle_keypress (self, keyval, keycode, mods, 
string);
        }
@@ -488,7 +493,8 @@ gtk_source_vim_state_synthesize (GtkSourceVimState *self,
 
        g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (self), FALSE);
 
-       keyval_to_string (keyval, mods, string);
+       gtk_source_vim_state_keyval_to_string (keyval, mods, string);
+
        return GTK_SOURCE_VIM_STATE_GET_CLASS (self)->handle_keypress (self, keyval, 0, mods, string);
 }
 
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index c18eb31b..2ade8ab1 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -96,6 +96,9 @@ void               gtk_source_vim_state_select                (GtkSourceVimState
                                                                const GtkTextIter *insert,
                                                                const GtkTextIter *selection);
 void               gtk_source_vim_state_place_cursor_onscreen (GtkSourceVimState *self);
+void               gtk_source_vim_state_keyval_to_string      (guint              keyval,
+                                                               GdkModifierType    mods,
+                                                               char               str[16]);
 
 static inline gboolean
 gtk_source_vim_state_is_escape (guint           keyval,


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