[gtksourceview/wip/chergert/vim: 269/293] cleanup prev line visual column




commit 19d0c2ef99ca2bcf5e46a2034d494f77ac0c699e
Author: Christian Hergert <chergert redhat com>
Date:   Wed Nov 3 16:11:41 2021 -0700

    cleanup prev line visual column

 gtksourceview/vim/gtk-source-vim-motion.c | 38 +++++++++----------------------
 1 file changed, 11 insertions(+), 27 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index c2b1149b..b65b606d 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -562,26 +562,6 @@ motion_prev_line_end (GtkTextIter        *iter,
        return TRUE;
 }
 
-static gboolean
-motion_prev_line (GtkTextIter        *iter,
-                  GtkSourceVimMotion *state)
-{
-       guint line = gtk_text_iter_get_line (iter);
-
-       if (line == 0)
-       {
-               gtk_text_iter_set_offset (iter, 0);
-               return TRUE;
-       }
-
-       gtk_text_buffer_get_iter_at_line (gtk_text_iter_get_buffer (iter), iter, line - 1);
-
-       if (!gtk_text_iter_starts_line (iter))
-               gtk_text_iter_set_line_offset (iter, 0);
-
-       return TRUE;
-}
-
 static gboolean
 motion_next_line_first_char (GtkTextIter        *iter,
                              GtkSourceVimMotion *state)
@@ -642,22 +622,26 @@ motion_next_line_visual_column (GtkTextIter        *iter,
 
 static gboolean
 motion_prev_line_visual_column (GtkTextIter        *iter,
-                                GtkSourceVimMotion *state)
+                                GtkSourceVimMotion *self)
 {
-       GtkSourceView *view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (state));
-       guint column;
-
-       state->invalidates_visual_column = FALSE;
+       GtkTextBuffer *buffer = gtk_text_iter_get_buffer (iter);
+       GtkSourceView *view = gtk_source_vim_state_get_view (GTK_SOURCE_VIM_STATE (self));
+       int column = gtk_source_vim_state_get_visual_column (GTK_SOURCE_VIM_STATE (self));
+       int count = get_adjusted_count (self);
+       int line = gtk_text_iter_get_line (iter);
 
-       column = gtk_source_vim_state_get_visual_column (GTK_SOURCE_VIM_STATE (state));
+       self->invalidates_visual_column = FALSE;
 
-       if (!motion_prev_line (iter, state))
+       if (self->apply_count != 1 || count == 0)
                return FALSE;
 
+       gtk_text_buffer_get_iter_at_line (buffer, iter, line - count);
        get_iter_at_visual_column (view, iter, column);
 
        if (!gtk_text_iter_starts_line (iter) && gtk_text_iter_ends_line (iter))
+       {
                gtk_text_iter_backward_char (iter);
+       }
 
        return TRUE;
 }


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