[gtksourceview] vim: pass ^W commands to execute-command signals



commit bcfde4dc406a0af96ec3d5c7a62046da0ec6646f
Author: Christian Hergert <chergert redhat com>
Date:   Mon Dec 13 13:17:51 2021 -0800

    vim: pass ^W commands to execute-command signals
    
    This allows applications to be able to handle them and perform various
    split window movements.

 gtksourceview/vim/gtksourcevimnormal.c | 24 ++++++++++++++++++++++--
 tests/test-vim.c                       |  2 +-
 2 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/vim/gtksourcevimnormal.c b/gtksourceview/vim/gtksourcevimnormal.c
index 4d9a6986..f3fe4f6f 100644
--- a/gtksourceview/vim/gtksourcevimnormal.c
+++ b/gtksourceview/vim/gtksourcevimnormal.c
@@ -999,9 +999,29 @@ key_handler_split (GtkSourceVimNormal *self,
                    GdkModifierType     mods,
                    const char         *string)
 {
+       GtkSourceVimState *root;
+
        g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
 
-       return TRUE;
+       switch (keyval)
+       {
+       case GDK_KEY_c:
+       case GDK_KEY_v:
+       case GDK_KEY_s:
+       case GDK_KEY_w:
+               if ((root = gtk_source_vim_state_get_root (GTK_SOURCE_VIM_STATE (self))) &&
+                   GTK_SOURCE_IS_VIM (root))
+               {
+                       gtk_source_vim_emit_execute_command (GTK_SOURCE_VIM (root), self->command_text->str);
+                       gtk_source_vim_normal_clear (self);
+                       return TRUE;
+               }
+
+               return gtk_source_vim_normal_bail (self);
+
+       default:
+               return FALSE;
+       }
 }
 
 static gboolean
@@ -1134,7 +1154,7 @@ key_handler_initial (GtkSourceVimNormal *self,
 
                        case GDK_KEY_w:
                                self->handler = key_handler_split;
-                               break;
+                               return TRUE;
 
                        case GDK_KEY_r:
                                self->handler = key_handler_command;
diff --git a/tests/test-vim.c b/tests/test-vim.c
index 7d873e3d..440cbcde 100644
--- a/tests/test-vim.c
+++ b/tests/test-vim.c
@@ -31,7 +31,7 @@ static gboolean
 execute_command (GtkSourceVimIMContext *context,
                  const char            *command)
 {
-       if (g_str_equal (command, ":q"))
+       if (g_str_equal (command, ":q") || g_str_equal (command, "^Wc"))
        {
                g_main_loop_quit (main_loop);
                return TRUE;


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