[gnome-builder] tab: Fix Escape in insert mode with completion shown



commit cecc060f0a6d53d11343496fa791a88ee723076f
Author: Christian Hergert <christian hergert me>
Date:   Tue Oct 14 13:32:48 2014 -0700

    tab: Fix Escape in insert mode with completion shown
    
    This makes the completion window hide and the editor go back to normal
    mode when Escape is pressed in insert mode with the completion window
    shown.
    
    This is closer to what VIM does internally (althouth we may want to make
    this configurable as well).

 src/editor/gb-editor-tab.c |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 8d99776..1986e80 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -1156,6 +1156,7 @@ gb_editor_tab_constructed (GObject *object)
   GbEditorTab *tab = (GbEditorTab *) object;
   GtkSourceGutter *gutter;
   GSettings *settings;
+  gboolean vim_enabled;
 
   ENTRY;
 
@@ -1163,12 +1164,29 @@ gb_editor_tab_constructed (GObject *object)
 
   priv = tab->priv;
 
+  settings = g_settings_new ("org.gnome.builder.editor");
+
   if (!priv->document)
     priv->document = gb_editor_document_new ();
 
   gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->source_view),
                             GTK_TEXT_BUFFER (priv->document));
 
+  /*
+   * WORKAROUND:
+   * 
+   * We need to connect VIM in the proper mode as early as possible
+   * so that our key-press-event signal is connected before the
+   * GtkSourceCompletion connects to key-press-event of the GtkSourceView.
+   * Otherwise, Escape when in insert mode may only hide the completion
+   * window and not escape us back into VIM normal mode as VIM would.
+   */
+  vim_enabled = g_settings_get_boolean (settings, "vim-mode");
+  priv->vim = g_object_new (GB_TYPE_EDITOR_VIM,
+                            "enabled", vim_enabled,
+                            "text-view", priv->source_view,
+                            NULL);
+
   priv->snippets_provider =
     g_object_new (GB_TYPE_SOURCE_SNIPPET_COMPLETION_PROVIDER,
                   "source-view", priv->source_view,
@@ -1318,10 +1336,6 @@ gb_editor_tab_constructed (GObject *object)
                     NULL);
   gtk_source_gutter_insert (gutter, priv->change_renderer, 0);
 
-  priv->vim = g_object_new (GB_TYPE_EDITOR_VIM,
-                            "enabled", FALSE,
-                            "text-view", priv->source_view,
-                            NULL);
   g_signal_connect (priv->vim,
                     "command-visibility-toggled",
                     G_CALLBACK (on_vim_command_visibility_toggled),
@@ -1339,15 +1353,15 @@ gb_editor_tab_constructed (GObject *object)
                     G_CALLBACK (on_vim_notify_mode),
                     tab);
 
-  settings = g_settings_new ("org.gnome.builder.editor");
   g_settings_bind (settings, "vim-mode", priv->vim, "enabled",
                    G_SETTINGS_BIND_DEFAULT);
   g_settings_bind (settings, "word-completion", tab, "enable-word-completion",
                    G_SETTINGS_BIND_DEFAULT);
-  g_object_unref (settings);
 
   gb_editor_tab_cursor_moved (tab, priv->document);
 
+  g_object_unref (settings);
+
   EXIT;
 }
 


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