[gnome-builder] sourceview: special case F keys during suppression



commit f3871604cd2555b7556c098f91339c6b1f5a66eb
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 20 03:41:00 2017 -0700

    sourceview: special case F keys during suppression
    
    The vim keybindings need to suppress unknown input. That can
    conflict with our keybindings. Previously we just looked at
    state to determine what to do, but now we need to ignore common
    keys that don't have modifiers such as the F keys.

 libide/sourceview/ide-source-view-mode.c |   31 ++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/libide/sourceview/ide-source-view-mode.c b/libide/sourceview/ide-source-view-mode.c
index 819e9a1..4ed2c0b 100644
--- a/libide/sourceview/ide-source-view-mode.c
+++ b/libide/sourceview/ide-source-view-mode.c
@@ -401,6 +401,33 @@ toplevel_is_offscreen (GdkWindow *window)
   return FALSE;
 }
 
+static gboolean
+can_supress (const GdkEventKey *event)
+{
+  /*
+   * This is rather tricky because we don't know what can be activated
+   * in the bubble up phase of event delivery. Looking at ->string isn't
+   * very safe when input methods are in play. So we just hard code some
+   * things we know about common keybindings.
+   *
+   * If you are wondering why you're getting beeps in the editor while
+   * activating some keybinding you've added, you found the right spot!
+   */
+  if ((event->state & GDK_MODIFIER_MASK) != 0)
+    return FALSE;
+
+  switch (event->keyval)
+    {
+    case GDK_KEY_F1: case GDK_KEY_F2: case GDK_KEY_F3: case GDK_KEY_F4:
+    case GDK_KEY_F5: case GDK_KEY_F6: case GDK_KEY_F7: case GDK_KEY_F8:
+    case GDK_KEY_F9: case GDK_KEY_F10: case GDK_KEY_F11: case GDK_KEY_F12:
+      return FALSE;
+
+    default:
+      return TRUE;
+    }
+}
+
 gboolean
 _ide_source_view_mode_do_event (IdeSourceViewMode *mode,
                                 GdkEventKey       *event,
@@ -447,8 +474,8 @@ _ide_source_view_mode_do_event (IdeSourceViewMode *mode,
 
     case IDE_SOURCE_VIEW_MODE_TYPE_PERMANENT:
       {
-        /* don't block possible accelerators, but supress others */
-        if (!handled && suppress_unbound && ((event->state & GDK_MODIFIER_MASK) == 0))
+        /* Don't block possible accelerators, but supress others. */
+        if (!handled && suppress_unbound && can_supress (event))
           {
             if (!is_modifier_key (event) && !toplevel_is_offscreen (event->window))
               gdk_window_beep (event->window);


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