[gtksourceview/wip/chergert/vim: 70/73] add page movements




commit 451a4ce5ef23d94f066a1fb8a5232d0aa136bb1a
Author: Christian Hergert <chergert redhat com>
Date:   Mon Oct 25 22:43:30 2021 -0700

    add page movements

 gtksourceview/vim/gtk-source-vim-normal.c | 12 ++++++++++++
 gtksourceview/vim/gtk-source-vim-state.c  | 30 +++++++++++++++++++++++-------
 gtksourceview/vim/gtk-source-vim-state.h  |  2 ++
 3 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 567e298d..ebdd140a 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -185,6 +185,16 @@ key_handler_viewport (GtkSourceVimNormal *self,
                                gtk_source_vim_normal_clear (self);
                                return TRUE;
 
+                       case GDK_KEY_f:
+                               gtk_source_vim_state_scroll_page (state, MAX (1, self->repeat));
+                               gtk_source_vim_normal_clear (self);
+                               return TRUE;
+
+                       case GDK_KEY_b:
+                               gtk_source_vim_state_scroll_page (state, MIN (-1, -self->repeat));
+                               gtk_source_vim_normal_clear (self);
+                               return TRUE;
+
                        default:
                                break;
                }
@@ -422,6 +432,8 @@ key_handler_initial (GtkSourceVimNormal *self,
                        case GDK_KEY_u:
                        case GDK_KEY_e:
                        case GDK_KEY_y:
+                       case GDK_KEY_f:
+                       case GDK_KEY_b:
                                self->handler = key_handler_viewport;
                                break;
 
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index f7d576f1..190df401 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -551,9 +551,10 @@ gtk_source_vim_state_scroll_line (GtkSourceVimState *self,
        gtk_text_view_place_cursor_onscreen (GTK_TEXT_VIEW (view));
 }
 
-void
-gtk_source_vim_state_scroll_half_page (GtkSourceVimState *self,
-                                       int                count)
+static void
+_gtk_source_vim_state_scroll_page (GtkSourceVimState *self,
+                                   int                count,
+                                   int                divisor)
 {
        GtkSourceView *view;
        GdkRectangle rect, loc;
@@ -562,6 +563,7 @@ gtk_source_vim_state_scroll_half_page (GtkSourceVimState *self,
        int visible_lines;
 
        g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
+       g_return_if_fail (divisor > 0);
 
        if (count == 0)
                count = 1;
@@ -574,20 +576,20 @@ gtk_source_vim_state_scroll_half_page (GtkSourceVimState *self,
        gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &bottom, rect.x, rect.y + rect.height);
 
        visible_lines = gtk_text_iter_get_line (&bottom) - gtk_text_iter_get_line (&top);
-       if (visible_lines < 2)
-               visible_lines = 2;
+       if (visible_lines < divisor)
+               visible_lines = divisor;
 
        gtk_text_view_get_iter_location (GTK_TEXT_VIEW (view), &iter, &loc);
        gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (view), GTK_TEXT_WINDOW_TEXT, loc.x, loc.y, 
&loc.x, &loc.y);
 
        if (count > 0)
        {
-               gtk_text_iter_forward_lines (&top, count * visible_lines);
+               gtk_text_iter_forward_lines (&top, count * visible_lines / divisor);
                _gtk_source_view_jump_to_iter (GTK_TEXT_VIEW (view), &top, 0.0, TRUE, 1.0, 0.0);
        }
        else
        {
-               gtk_text_iter_backward_lines (&bottom, -count * visible_lines);
+               gtk_text_iter_backward_lines (&bottom, -count * visible_lines / divisor);
                _gtk_source_view_jump_to_iter (GTK_TEXT_VIEW (view), &bottom, 0.0, TRUE, 1.0, 1.0);
        }
 
@@ -595,3 +597,17 @@ gtk_source_vim_state_scroll_half_page (GtkSourceVimState *self,
        gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, loc.x, loc.y);
        gtk_source_vim_state_select (self, &iter, &iter);
 }
+
+void
+gtk_source_vim_state_scroll_half_page (GtkSourceVimState *self,
+                                       int                count)
+{
+       return _gtk_source_vim_state_scroll_page (self, count, 2);
+}
+
+void
+gtk_source_vim_state_scroll_page (GtkSourceVimState *self,
+                                  int                count)
+{
+       return _gtk_source_vim_state_scroll_page (self, count, 1);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 24b07e30..2a0578d4 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -77,6 +77,8 @@ gboolean           gtk_source_vim_state_synthesize        (GtkSourceVimState *se
 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,


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