[gtksourceview/wip/chergert/vim: 239/293] track operations that dont alter visible column




commit aa6a6c745192ab617f159a82f6cabaf37d85512b
Author: Christian Hergert <chergert redhat com>
Date:   Tue Nov 2 19:53:30 2021 -0700

    track operations that dont alter visible column
    
    the goal here is that j/k don't alter your visible column so you can
    move down and stay on right position even after empty lines.

 gtksourceview/vim/gtk-source-vim-motion.c | 27 +++++++++++++++++----------
 gtksourceview/vim/gtk-source-vim-motion.h |  1 +
 2 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index ba7a2050..7bb3f6c6 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -79,6 +79,8 @@ struct _GtkSourceVimMotion
 
        /* If we're to apply inclusivity (used by chained motions) */
        guint applying_inclusive : 1;
+
+       guint invalidates_visual_column : 1;
 };
 
 G_DEFINE_TYPE (GtkSourceVimMotion, gtk_source_vim_motion, GTK_SOURCE_TYPE_VIM_STATE)
@@ -591,11 +593,9 @@ motion_next_line_visual_column (GtkTextIter        *iter,
        guint line = gtk_text_iter_get_line (iter);
        guint column;
 
-       /* TODO: We need a way to persist the visual column across
-        * multiple motion movements so that we don't break when
-        * we come across an empty column.
-        */
-       column = gtk_source_view_get_visual_column (view, iter);
+       state->invalidates_visual_column = FALSE;
+
+       column = gtk_source_vim_state_get_visual_column (GTK_SOURCE_VIM_STATE (state));
 
        gtk_text_iter_set_line (iter, line + 1);
        get_iter_at_visual_column (view, iter, column);
@@ -613,11 +613,9 @@ motion_prev_line_visual_column (GtkTextIter        *iter,
        GtkSourceView *view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (state));
        guint column;
 
-       /* TODO: We need a way to persist the visual column across
-        * multiple motion movements so that we don't break when
-        * we come across an empty column.
-        */
-       column = gtk_source_view_get_visual_column (view, iter);
+       state->invalidates_visual_column = FALSE;
+
+       column = gtk_source_vim_state_get_visual_column (GTK_SOURCE_VIM_STATE (state));
 
        if (!motion_prev_line (iter, state))
                return FALSE;
@@ -1530,6 +1528,7 @@ gtk_source_vim_motion_init (GtkSourceVimMotion *self)
 {
        self->apply_on_leave = TRUE;
        self->command_text = g_string_new (NULL);
+       self->invalidates_visual_column = TRUE;
 }
 
 gboolean
@@ -1827,3 +1826,11 @@ gtk_source_vim_motion_chain (GtkSourceVimMotion *self,
 
        return GTK_SOURCE_VIM_STATE (chained);
 }
+
+gboolean
+gtk_source_vim_motion_invalidates_visual_column (GtkSourceVimMotion *self)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_VIM_MOTION (self), FALSE);
+
+       return self->invalidates_visual_column;
+}
diff --git a/gtksourceview/vim/gtk-source-vim-motion.h b/gtksourceview/vim/gtk-source-vim-motion.h
index ec10ec22..07b1cdcf 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.h
+++ b/gtksourceview/vim/gtk-source-vim-motion.h
@@ -49,5 +49,6 @@ void               gtk_source_vim_motion_set_mark                  (GtkSourceVim
 gboolean           gtk_source_vim_motion_apply                     (GtkSourceVimMotion *self,
                                                                     GtkTextIter        *iter,
                                                                     gboolean            apply_inclusive);
+gboolean           gtk_source_vim_motion_invalidates_visual_column (GtkSourceVimMotion *self);
 
 G_END_DECLS


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