[gnome-builder] source-view: make Tab prefer snippet movement before completion



commit 4ba13a05699fa3976b56db28c9ba43ed92c3d2a2
Author: Christian Hergert <chergert redhat com>
Date:   Mon Nov 7 14:55:10 2016 -0800

    source-view: make Tab prefer snippet movement before completion
    
    When we are in a snippet, such as those from function parameter completion,
    we would much rather prefer to use tab to move to the next snippet location
    not complete the (possibly overactive) completion list.
    
    We might need to revisit all of this as we make completion much better
    about completing symbols in scope that might work, but this is better
    for what we have today.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774073

 libide/sourceview/ide-source-view.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/libide/sourceview/ide-source-view.c b/libide/sourceview/ide-source-view.c
index 057711f..547b23b 100644
--- a/libide/sourceview/ide-source-view.c
+++ b/libide/sourceview/ide-source-view.c
@@ -2363,6 +2363,22 @@ ide_source_view_key_press_event (GtkWidget   *widget,
         }
     }
 
+  /*
+   * We have stolen ownership of Tab from GtkSourceCompletion so that we can
+   * move between snippets at a higher priority than the completion window.
+   * If we don't have a snippet active
+   */
+  if (priv->completion_visible && event->keyval == GDK_KEY_Tab)
+    {
+      GtkSourceCompletion *completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (self));
+      g_signal_emit_by_name (completion, "activate-proposal");
+      return TRUE;
+    }
+
+  /*
+   * Avoid conflicts with global <alt>+N perspective movements.
+   * We might want to adjust those keybindings at somepoint.
+   */
   if (priv->completion_visible && event->state == GDK_MOD1_MASK)
     {
       if ((event->keyval >= GDK_KEY_0 && event->keyval <= GDK_KEY_9) ||
@@ -6846,10 +6862,15 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
    * keybindings may want to control that manually (such as Vim). Vim needs to
    * go back to normal mode upon Escape to more closely match the traditional
    * environment.
+   *
+   * We remove the Tab activation from the completion class so that we can
+   * activate it ourselves. Otherwise, it might fire before we have a chance
+   * to steal it to move to the next completion item.
    */
   completion_class = g_type_class_ref (GTK_SOURCE_TYPE_COMPLETION);
   binding_set = gtk_binding_set_by_class (completion_class);
   gtk_binding_entry_remove (binding_set, GDK_KEY_Escape, 0);
+  gtk_binding_entry_remove (binding_set, GDK_KEY_Tab, 0);
   g_type_class_unref (completion_class);
 }
 


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