[gtksourceview/wip/chergert/vim: 165/363] stub out some visual bits




commit 93df2c67721fd80cb2ceada1314c02f4d1021265
Author: Christian Hergert <chergert redhat com>
Date:   Sat Oct 30 12:57:38 2021 -0700

    stub out some visual bits

 gtksourceview/vim/gtk-source-vim-visual.c | 67 +++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index 83bbca26..02a829e2 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -33,6 +33,72 @@ struct _GtkSourceVimVisual
 
 G_DEFINE_TYPE (GtkSourceVimVisual, gtk_source_vim_visual, GTK_SOURCE_TYPE_VIM_STATE)
 
+static void
+extend_lines (GtkTextIter *a,
+              GtkTextIter *b)
+{
+       if (gtk_text_iter_equal (a, b))
+       {
+               gtk_text_iter_set_line_offset (a, 0);
+               if (!gtk_text_iter_ends_line (b))
+                       gtk_text_iter_forward_to_line_end (b);
+       }
+       else if (gtk_text_iter_compare (a, b) < 0)
+       {
+               gtk_text_iter_set_line_offset (a, 0);
+               if (!gtk_text_iter_ends_line (b))
+                       gtk_text_iter_forward_to_line_end (b);
+       }
+       else
+       {
+               gtk_text_iter_set_line_offset (b, 0);
+               if (!gtk_text_iter_ends_line (a))
+                       gtk_text_iter_forward_to_line_end (a);
+       }
+}
+
+static void
+gtk_source_vim_visual_extend_selection (GtkSourceVimVisual *self)
+{
+       GtkSourceBuffer *buffer;
+       GtkTextIter iter;
+       GtkTextIter selection;
+
+       g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
+
+       buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
+
+       switch (self->mode)
+       {
+               case GTK_SOURCE_VIM_VISUAL_LINE:
+                       extend_lines (&iter, &selection);
+                       break;
+
+               case GTK_SOURCE_VIM_VISUAL_CHAR:
+                       if (gtk_text_iter_equal (&iter, &selection))
+                       {
+                               gtk_text_iter_forward_char (&iter);
+                       }
+                       break;
+
+               case GTK_SOURCE_VIM_VISUAL_BLOCK:
+               default:
+                       break;
+       }
+
+       gtk_source_vim_state_select (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
+}
+
+static void
+gtk_source_vim_visual_enter (GtkSourceVimState *state)
+{
+       GtkSourceVimVisual *self = (GtkSourceVimVisual *)state;
+
+       g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
+
+       gtk_source_vim_visual_extend_selection (self);
+}
+
 static const char *
 gtk_source_vim_visual_get_command_bar_text (GtkSourceVimState *state)
 {
@@ -94,6 +160,7 @@ gtk_source_vim_visual_class_init (GtkSourceVimVisualClass *klass)
 
        state_class->get_command_bar_text = gtk_source_vim_visual_get_command_bar_text;
        state_class->handle_keypress = gtk_source_vim_visual_handle_keypress;
+       state_class->enter = gtk_source_vim_visual_enter;
 }
 
 static void


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