[gtksourceview/wip/chergert/vim] add zz zt and zb



commit 99d6471667cb39510377540d36dceb1d658d7d06
Author: Christian Hergert <chergert redhat com>
Date:   Tue Oct 26 16:34:25 2021 -0700

    add zz zt and zb

 gtksourceview/vim/gtk-source-vim-normal.c | 37 ++++++++++++++++++++++++++++++-
 gtksourceview/vim/gtk-source-vim-state.c  | 15 +++++++++++++
 gtksourceview/vim/gtk-source-vim-state.h  |  2 ++
 3 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index ebdd140a..4cc02743 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -150,6 +150,40 @@ key_handler_command (GtkSourceVimNormal *self,
        return TRUE;
 }
 
+static gboolean
+key_handler_z (GtkSourceVimNormal *self,
+               guint               keyval,
+               guint               keycode,
+               GdkModifierType     mods,
+               const char         *string)
+{
+       GtkSourceVimState *state = (GtkSourceVimState *)self;
+
+       g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+
+       switch (keyval)
+       {
+               case GDK_KEY_z:
+                       gtk_source_vim_state_z_scroll (state, 0.5);
+                       break;
+
+               case GDK_KEY_b:
+                       gtk_source_vim_state_z_scroll (state, 1.0);
+                       break;
+
+               case GDK_KEY_t:
+                       gtk_source_vim_state_z_scroll (state, 0.0);
+                       break;
+
+               default:
+                       return gtk_source_vim_normal_bail (self);
+       }
+
+       gtk_source_vim_normal_clear (self);
+
+       return TRUE;
+}
+
 static gboolean
 key_handler_viewport (GtkSourceVimNormal *self,
                       guint               keyval,
@@ -203,7 +237,8 @@ key_handler_viewport (GtkSourceVimNormal *self,
        switch (keyval)
        {
                case GDK_KEY_z:
-                       break;
+                       self->handler = key_handler_z;
+                       return TRUE;
 
                default:
                        break;
diff --git a/gtksourceview/vim/gtk-source-vim-state.c b/gtksourceview/vim/gtk-source-vim-state.c
index 9ba952da..538dcc5c 100644
--- a/gtksourceview/vim/gtk-source-vim-state.c
+++ b/gtksourceview/vim/gtk-source-vim-state.c
@@ -704,3 +704,18 @@ gtk_source_vim_state_place_cursor_onscreen (GtkSourceVimState *self)
                gtk_source_vim_state_select (self, &iter, &iter);
        }
 }
+
+void
+gtk_source_vim_state_z_scroll (GtkSourceVimState *self,
+                               double             yalign)
+{
+       GtkSourceView *view;
+       GtkTextIter iter;
+
+       g_return_if_fail (GTK_SOURCE_IS_VIM_STATE (self));
+
+       gtk_source_vim_state_get_buffer (self, &iter, NULL);
+       view = gtk_source_vim_state_get_view (self);
+
+       gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &iter, 0, TRUE, 1.0, yalign);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-state.h b/gtksourceview/vim/gtk-source-vim-state.h
index 62e7c93f..04ec22be 100644
--- a/gtksourceview/vim/gtk-source-vim-state.h
+++ b/gtksourceview/vim/gtk-source-vim-state.h
@@ -83,6 +83,8 @@ void               gtk_source_vim_state_scroll_half_page      (GtkSourceVimState
                                                                int                count);
 void               gtk_source_vim_state_scroll_line           (GtkSourceVimState *self,
                                                                int                count);
+void               gtk_source_vim_state_z_scroll              (GtkSourceVimState *self,
+                                                               double             yalign);
 void               gtk_source_vim_state_select                (GtkSourceVimState *self,
                                                                const GtkTextIter *insert,
                                                                const GtkTextIter *selection);


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