[gtksourceview/wip/chergert/vim] handle half page movements in visual



commit b5ad5c2a1198a93b5d2b4e4962d91bdd003eb201
Author: Christian Hergert <chergert redhat com>
Date:   Wed Nov 3 13:13:46 2021 -0700

    handle half page movements in visual

 gtksourceview/vim/gtk-source-vim-motion.c | 39 +++++++++++++++++++++++++++++++
 gtksourceview/vim/gtk-source-vim-visual.c | 19 +++++++++++++++
 2 files changed, 58 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index ec9b4e2e..bc704118 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -1126,6 +1126,39 @@ motion_prev_scroll_page (GtkTextIter        *iter,
        return TRUE;
 }
 
+static gboolean
+motion_next_scroll_half_page (GtkTextIter        *iter,
+                              GtkSourceVimMotion *self)
+{
+       int count = get_adjusted_count (self);
+       GtkTextBuffer *buffer = gtk_text_iter_get_buffer (iter);
+       GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
+
+       if (self->apply_count != 1)
+               return FALSE;
+
+       gtk_source_vim_state_scroll_half_page (GTK_SOURCE_VIM_STATE (self), count);
+       gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), iter, insert);
+
+       return TRUE;
+}
+
+static gboolean
+motion_prev_scroll_half_page (GtkTextIter        *iter,
+                              GtkSourceVimMotion *self)
+{
+       int count = get_adjusted_count (self);
+       GtkTextBuffer *buffer = gtk_text_iter_get_buffer (iter);
+       GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
+
+       if (self->apply_count != 1)
+               return FALSE;
+
+       gtk_source_vim_state_scroll_half_page (GTK_SOURCE_VIM_STATE (self), -count);
+       gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), iter, insert);
+       return TRUE;
+}
+
 static gboolean
 motion_prev_scroll_line (GtkTextIter        *iter,
                          GtkSourceVimMotion *self)
@@ -1325,6 +1358,12 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
                        case GDK_KEY_y:
                                return gtk_source_vim_motion_complete (self, motion_prev_scroll_line, 
INCLUSIVE, LINEWISE);
 
+                       case GDK_KEY_u:
+                               return gtk_source_vim_motion_complete (self, motion_prev_scroll_half_page, 
INCLUSIVE, LINEWISE);
+
+                       case GDK_KEY_d:
+                               return gtk_source_vim_motion_complete (self, motion_next_scroll_half_page, 
INCLUSIVE, LINEWISE);
+
                        default:
                                break;
                }
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index 96b38e3a..d358d3d7 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -428,6 +428,23 @@ key_handler_initial (GtkSourceVimVisual *self,
 {
        g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
 
+       if ((mods & GDK_CONTROL_MASK) != 0)
+       {
+               switch (keyval)
+               {
+                       case GDK_KEY_y:
+                       case GDK_KEY_e:
+                       case GDK_KEY_b:
+                       case GDK_KEY_f:
+                       case GDK_KEY_u:
+                       case GDK_KEY_d:
+                               goto try_visual_motion;
+
+                       default:
+                               break;
+               }
+       }
+
        switch (keyval)
        {
                case GDK_KEY_z:
@@ -478,6 +495,8 @@ key_handler_initial (GtkSourceVimVisual *self,
                        break;
        }
 
+try_visual_motion:
+
        return gtk_source_vim_visual_try_motion (self, keyval, keycode, mods, string);
 }
 


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