[gnome-builder] vim: Escape keypress with completion window returns to normal mode



commit 76221de49770c04df3c4d8d7c5c8693e403c9a06
Author: Christian Hergert <chergert redhat com>
Date:   Thu Oct 15 13:44:02 2015 -0700

    vim: Escape keypress with completion window returns to normal mode
    
    If we are in insert mode, and have pressed Escape, we should leave insert
    mode and return to normal mode. This requires hijacking the binding entry
    from GtkSourceCompletion, but seems to work rather nicely.

 data/keybindings/default.css |    3 ++-
 data/keybindings/emacs.css   |    3 ++-
 data/keybindings/vim.css     |    4 ++++
 libide/ide-source-view.c     |    6 ++++++
 4 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/data/keybindings/default.css b/data/keybindings/default.css
index 1eeb5bc..6b14fb1 100644
--- a/data/keybindings/default.css
+++ b/data/keybindings/default.css
@@ -6,7 +6,8 @@
                   "clear-modifier" ()
                   "clear-selection" ()
                   "clear-count" ()
-                  "clear-snippets" () };
+                  "clear-snippets" ()
+                  "hide-completion" () };
   bind "<ctrl>comma" { "action" ("app", "preferences", "") };
   bind "<ctrl>f" { "action" ("frame", "find", "3") };
   bind "<ctrl>period" { "action" ("workbench", "global-search", "") };
diff --git a/data/keybindings/emacs.css b/data/keybindings/emacs.css
index a0d46eb..7ca9841 100644
--- a/data/keybindings/emacs.css
+++ b/data/keybindings/emacs.css
@@ -52,7 +52,8 @@
                   "clear-modifier" ()
                   "clear-selection" ()
                   "clear-count" ()
-                  "clear-snippets" () };
+                  "clear-snippets" ()
+                  "hide-completion" () };
   bind "<ctrl>x" { "set-mode" ("emacs-x", transient) };
   bind "<ctrl>underscore" { "undo" () };
   bind "<alt>x" { "action" ("win", "show-command-bar", "") };
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 4b4da2b..92c50b7 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -83,12 +83,14 @@
                   "clear-count" ()
                   "clear-selection" ()
                   "clear-snippets" ()
+                  "hide-completion" ()
                   "set-mode" ("vim-normal", permanent) };
   bind "<ctrl>bracketleft" { "end-macro" ()
                              "set-overwrite" (0)
                              "clear-count" ()
                              "clear-selection" ()
                              "clear-snippets" ()
+                             "hide-completion" ()
                              "set-mode" ("vim-normal", permanent) };
 
   bind "<ctrl>comma" { "action" ("app", "preferences", "") };
@@ -1174,6 +1176,7 @@
                   "clear-count" ()
                   "clear-selection" ()
                   "clear-snippets" ()
+                  "hide-completion" ()
                   "movement" (previous-char, 0, 1, 0)
                   "set-mode" ("vim-normal", permanent) };
   bind "<ctrl>bracketleft" { "end-macro" ()
@@ -1181,6 +1184,7 @@
                              "clear-count" ()
                              "clear-selection" ()
                              "clear-snippets" ()
+                             "hide-completion" ()
                              "movement" (previous-char, 0, 1, 0)
                              "set-mode" ("vim-normal", permanent) };
 }
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 8638482..61b8261 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -6259,10 +6259,16 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
    * to accidentally activate. Therefore, we are switching to just Tab or the
    * <Alt>Number accelerators. For example, "void<Return>" can easily activate
    * search results like "voidfp" or "voidId".
+   *
+   * Escape is wired up by the GtkSourceCompletion by default. However, some
+   * 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.
    */
   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_Return, 0);
+  gtk_binding_entry_remove (binding_set, GDK_KEY_Escape, 0);
   g_type_class_unref (completion_class);
 }
 


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