[gtksourceview/wip/chergert/vim: 72/73] use place cursor onscreen replacement




commit 57751baeb05d37c7f2c8b68f08f20cf3520ea647
Author: Christian Hergert <chergert redhat com>
Date:   Mon Oct 25 23:30:11 2021 -0700

    use place cursor onscreen replacement
    
    since the gtk one seems broken, and not quite what we want anyway.

 gtksourceview/vim/gtk-source-vim-state.c | 44 ++++++++++-----------
 gtksourceview/vim/gtk-source-vim-state.h | 65 ++++++++++++++++----------------
 2 files changed, 56 insertions(+), 53 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 9ebc56c4..837d732d 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -542,13 +542,7 @@ gtk_source_vim_state_scroll_line (GtkSourceVimState *self,
 
        _gtk_source_view_jump_to_iter (GTK_TEXT_VIEW (view), &top, 0.0, TRUE, 1.0, 0.0);
 
-       /* Note: This doesn't seem to update immediate for CTRL+Y, probably
-        * because the viewport area has not calculated that the insert
-        * mark has fully moved off screen. We might need to do something
-        * like force revalidation but delaying the movement can cause
-        * ordering issues.
-        */
-       gtk_text_view_place_cursor_onscreen (GTK_TEXT_VIEW (view));
+       gtk_source_vim_state_place_cursor_onscreen (self);
 }
 
 void
@@ -627,26 +621,14 @@ scroll_page_up (GtkSourceVimState *self)
 }
 
 void
-gtk_source_vim_state_scroll_page (GtkSourceVimState *self,
-                                  int                count)
+gtk_source_vim_state_place_cursor_onscreen (GtkSourceVimState *self)
 {
        GtkSourceVimStatePrivate *priv = gtk_source_vim_state_get_instance_private (self);
        GtkTextIter iter;
        GdkRectangle rect, loc;
        gboolean move_insert = FALSE;
 
-       g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
-
-       if (count == 0)
-               count = 1;
-
-       for (int i = 1; i <= ABS (count); i++)
-       {
-               if (count > 0)
-                       scroll_page_down (self);
-               else
-                       scroll_page_up (self);
-       }
+       g_assert (GTK_SOURCE_IS_VIM_STATE (self));
 
        gtk_source_vim_state_get_buffer (self, &iter, NULL);
        gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (priv->view), &rect);
@@ -679,3 +661,23 @@ gtk_source_vim_state_scroll_page (GtkSourceVimState *self,
                gtk_source_vim_state_select (self, &iter, &iter);
        }
 }
+
+void
+gtk_source_vim_state_scroll_page (GtkSourceVimState *self,
+                                  int                count)
+{
+       g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
+
+       if (count == 0)
+               count = 1;
+
+       for (int i = 1; i <= ABS (count); i++)
+       {
+               if (count > 0)
+                       scroll_page_down (self);
+               else
+                       scroll_page_up (self);
+       }
+
+       gtk_source_vim_state_place_cursor_onscreen (self);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 2a0578d4..62e7c93f 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -54,38 +54,39 @@ struct _GtkSourceVimStateClass
                                     int                repeat);
 };
 
-void               gtk_source_vim_state_push              (GtkSourceVimState *self,
-                                                           GtkSourceVimState *new_state);
-void               gtk_source_vim_state_pop               (GtkSourceVimState *self);
-void               gtk_source_vim_state_beep              (GtkSourceVimState *self);
-GtkSourceVimState *gtk_source_vim_state_get_child         (GtkSourceVimState *self);
-GtkSourceVimState *gtk_source_vim_state_get_current       (GtkSourceVimState *self);
-GtkSourceView     *gtk_source_vim_state_get_view          (GtkSourceVimState *self);
-GtkSourceBuffer   *gtk_source_vim_state_get_buffer        (GtkSourceVimState *self,
-                                                           GtkTextIter       *insert,
-                                                           GtkTextIter       *selection_bound);
-GtkSourceVimState *gtk_source_vim_state_get_root          (GtkSourceVimState *self);
-GtkSourceVimState *gtk_source_vim_state_get_parent        (GtkSourceVimState *self);
-gboolean           gtk_source_vim_state_handle_event      (GtkSourceVimState *self,
-                                                           GdkEvent          *event);
-void               gtk_source_vim_state_set_overwrite     (GtkSourceVimState *self,
-                                                           gboolean           overwrite);
-gboolean           gtk_source_vim_state_get_can_repeat    (GtkSourceVimState *self);
-gboolean           gtk_source_vim_state_synthesize        (GtkSourceVimState *self,
-                                                           guint              keyval,
-                                                           GdkModifierType    mods);
-void               gtk_source_vim_state_repeat            (GtkSourceVimState *self,
-                                                           int                repeat);
-int                gtk_source_vim_state_get_visible_lines (GtkSourceVimState *self);
-void               gtk_source_vim_state_scroll_page       (GtkSourceVimState *self,
-                                                           int                count);
-void               gtk_source_vim_state_scroll_half_page  (GtkSourceVimState *self,
-                                                           int                count);
-void               gtk_source_vim_state_scroll_line       (GtkSourceVimState *self,
-                                                           int                count);
-void               gtk_source_vim_state_select            (GtkSourceVimState *self,
-                                                           const GtkTextIter *insert,
-                                                           const GtkTextIter *selection);
+void               gtk_source_vim_state_push                  (GtkSourceVimState *self,
+                                                               GtkSourceVimState *new_state);
+void               gtk_source_vim_state_pop                   (GtkSourceVimState *self);
+void               gtk_source_vim_state_beep                  (GtkSourceVimState *self);
+GtkSourceVimState *gtk_source_vim_state_get_child             (GtkSourceVimState *self);
+GtkSourceVimState *gtk_source_vim_state_get_current           (GtkSourceVimState *self);
+GtkSourceView     *gtk_source_vim_state_get_view              (GtkSourceVimState *self);
+GtkSourceBuffer   *gtk_source_vim_state_get_buffer            (GtkSourceVimState *self,
+                                                               GtkTextIter       *insert,
+                                                               GtkTextIter       *selection_bound);
+GtkSourceVimState *gtk_source_vim_state_get_root              (GtkSourceVimState *self);
+GtkSourceVimState *gtk_source_vim_state_get_parent            (GtkSourceVimState *self);
+gboolean           gtk_source_vim_state_handle_event          (GtkSourceVimState *self,
+                                                               GdkEvent          *event);
+void               gtk_source_vim_state_set_overwrite         (GtkSourceVimState *self,
+                                                               gboolean           overwrite);
+gboolean           gtk_source_vim_state_get_can_repeat        (GtkSourceVimState *self);
+gboolean           gtk_source_vim_state_synthesize            (GtkSourceVimState *self,
+                                                               guint              keyval,
+                                                               GdkModifierType    mods);
+void               gtk_source_vim_state_repeat                (GtkSourceVimState *self,
+                                                               int                repeat);
+int                gtk_source_vim_state_get_visible_lines     (GtkSourceVimState *self);
+void               gtk_source_vim_state_scroll_page           (GtkSourceVimState *self,
+                                                               int                count);
+void               gtk_source_vim_state_scroll_half_page      (GtkSourceVimState *self,
+                                                               int                count);
+void               gtk_source_vim_state_scroll_line           (GtkSourceVimState *self,
+                                                               int                count);
+void               gtk_source_vim_state_select                (GtkSourceVimState *self,
+                                                               const GtkTextIter *insert,
+                                                               const GtkTextIter *selection);
+void               gtk_source_vim_state_place_cursor_onscreen (GtkSourceVimState *self);
 
 static inline gboolean
 gtk_source_vim_state_is_escape (guint           keyval,


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