[gtksourceview/wip/chergert/vim: 67/73] scroll insert mark onscreen after motions




commit 66b9d39cbcfeb4ca62b64b473dff24d108f3b026
Author: Christian Hergert <chergert redhat com>
Date:   Mon Oct 25 19:15:40 2021 -0700

    scroll insert mark onscreen after motions

 gtksourceview/vim/gtk-source-vim-normal.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 81f4bff3..43782077 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -558,10 +558,17 @@ gtk_source_vim_normal_resume (GtkSourceVimState *state,
                               GtkSourceVimState *from)
 {
        GtkSourceVimNormal *self = (GtkSourceVimNormal *)state;
+       GtkSourceBuffer *buffer;
+       GtkSourceView *view;
+       GtkTextMark *insert;
 
        g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
        g_assert (GTK_SOURCE_IS_VIM_STATE (from));
 
+       buffer = gtk_source_vim_state_get_buffer (state, NULL, NULL);
+       insert = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer));
+       view = gtk_source_vim_state_get_view (state);
+
        if (self->repeat > 1)
        {
                gtk_source_vim_state_repeat (from, self->repeat - 1);
@@ -571,21 +578,24 @@ gtk_source_vim_normal_resume (GtkSourceVimState *state,
        if (GTK_SOURCE_IS_VIM_INSERT (from) ||
            GTK_SOURCE_IS_VIM_REPLACE (from))
        {
-               GtkSourceBuffer *buffer;
-               GtkTextIter insert;
+               GtkTextIter iter;
 
-               buffer = gtk_source_vim_state_get_buffer (state, &insert, NULL);
+               gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer),
+                                                 &iter, insert);
 
-               if (!gtk_text_iter_starts_line (&insert) &&
-                   gtk_text_iter_backward_char (&insert))
+               if (!gtk_text_iter_starts_line (&iter) &&
+                   gtk_text_iter_backward_char (&iter))
                {
                        gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
-                                                     &insert, &insert);
+                                                     &iter, &iter);
                }
        }
 
        gtk_source_vim_normal_clear (GTK_SOURCE_VIM_NORMAL (state));
        gtk_source_vim_state_set_overwrite (state, TRUE);
+
+       /* Always scroll the insert mark onscreen */
+       gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view), insert);
 }
 
 static void


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