[gtksourceview/wip/chergert/vim: 184/293] allow replaying last visual




commit 1234caf4e70941c3c1f956112d222c36bd9c3ce5
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 30 15:57:41 2021 -0700

    allow replaying last visual
    
    this allows you to exit visual mode, then type gv to renter it. If text
    has been entered between the marks, the range will expand just as it does
    in VIM.

 gtksourceview/vim/gtk-source-vim-normal.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 2597390a..74788ff7 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -44,6 +44,7 @@ struct _GtkSourceVimNormal
        GtkSourceVimState  parent_instance;
        GString           *command_text;
        GtkSourceVimState *repeat;
+       GtkSourceVimState *last_visual;
        KeyHandler         handler;
        int                count;
        guint              has_count : 1;
@@ -725,6 +726,14 @@ key_handler_g (GtkSourceVimNormal *self,
                        gtk_source_vim_state_synthesize (new_state, keyval, mods);
                        return TRUE;
 
+               case GDK_KEY_v:
+                       if (self->last_visual == NULL)
+                               return gtk_source_vim_normal_bail (self);
+
+                       new_state = gtk_source_vim_visual_clone (GTK_SOURCE_VIM_VISUAL (self->last_visual));
+                       gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), new_state);
+                       return TRUE;
+
                default:
                        return gtk_source_vim_normal_bail (self);
        }
@@ -994,6 +1003,12 @@ gtk_source_vim_normal_resume (GtkSourceVimState *state,
                go_backward_char (self);
        }
 
+       if (GTK_SOURCE_IS_VIM_VISUAL (from))
+       {
+               /* Store last visual around for reselection in gv */
+               g_set_object (&self->last_visual, from);
+       }
+
        /* Always scroll the insert mark onscreen */
        gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view), insert);
 
@@ -1033,6 +1048,7 @@ gtk_source_vim_normal_dispose (GObject *object)
 {
        GtkSourceVimNormal *self = (GtkSourceVimNormal *)object;
 
+       g_clear_object (&self->last_visual);
        g_clear_object (&self->repeat);
        g_string_free (self->command_text, TRUE);
        self->command_text = NULL;


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