[gtksourceview/wip/chergert/vim: 34/293] move to position 0 with ctrl+u in replace mode




commit 0a18f9cc827fbf552196869d38017348f6c06710
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 22 10:56:54 2021 -0700

    move to position 0 with ctrl+u in replace mode

 gtksourceview/vim/gtk-source-vim-replace.c | 32 +++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-replace.c b/gtksourceview/vim/gtk-source-vim-replace.c
index d0046d42..4dd433d8 100644
--- a/gtksourceview/vim/gtk-source-vim-replace.c
+++ b/gtksourceview/vim/gtk-source-vim-replace.c
@@ -22,6 +22,7 @@
 #include "config.h"
 
 #include "gtk-source-vim-replace.h"
+#include "gtk-source-vim-insert-literal.h"
 
 struct _GtkSourceVimReplace
 {
@@ -36,6 +37,19 @@ gtk_source_vim_replace_new (void)
        return g_object_new (GTK_SOURCE_TYPE_VIM_REPLACE, NULL);
 }
 
+static void
+move_to_zero (GtkSourceVimReplace *self)
+{
+       GtkSourceBuffer *buffer;
+       GtkTextIter insert;
+
+       g_assert (GTK_SOURCE_IS_VIM_REPLACE (self));
+
+       buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &insert, NULL);
+       gtk_text_iter_set_line_offset (&insert, 0);
+       gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &insert, &insert);
+}
+
 static gboolean
 gtk_source_vim_replace_handle_keypress (GtkSourceVimState *state,
                                         guint              keyval,
@@ -43,7 +57,9 @@ gtk_source_vim_replace_handle_keypress (GtkSourceVimState *state,
                                         GdkModifierType    mods,
                                         const char        *string)
 {
-       g_assert (GTK_SOURCE_IS_VIM_REPLACE (state));
+       GtkSourceVimReplace *self = (GtkSourceVimReplace *)state;
+
+       g_assert (GTK_SOURCE_IS_VIM_REPLACE (self));
 
        if (gtk_source_vim_state_is_escape (keyval, mods))
        {
@@ -51,6 +67,20 @@ gtk_source_vim_replace_handle_keypress (GtkSourceVimState *state,
                return TRUE;
        }
 
+       /* Now handle our commands */
+       if ((mods & GDK_CONTROL_MASK) != 0)
+       {
+               switch (keyval)
+               {
+                       case GDK_KEY_u:
+                               move_to_zero (self);
+                               return TRUE;
+
+                       default:
+                               break;
+               }
+       }
+
        return FALSE;
 }
 


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