[gtksourceview/wip/chergert/vim: 91/293] add some more movement ctors
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 91/293] add some more movement ctors
- Date: Fri, 5 Nov 2021 04:22:59 +0000 (UTC)
commit c007e1f6f57da3895bffd0284cc6b566ea32c2a3
Author: Christian Hergert <chergert redhat com>
Date: Wed Oct 27 11:34:31 2021 -0700
add some more movement ctors
gtksourceview/vim/gtk-source-vim-motion.c | 60 +++++++++++++++++++++++++++----
gtksourceview/vim/gtk-source-vim-motion.h | 18 +++++-----
2 files changed, 64 insertions(+), 14 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 47259608..0e201d34 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -453,22 +453,48 @@ motion_backward_char_same_line (GtkTextIter *iter,
return FALSE;
}
+static gboolean
+motion_prev_line_end (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_ends_line (iter))
+ gtk_text_iter_forward_to_line_end (iter);
+
+ /* Place on last character, not \n */
+ if (!gtk_text_iter_starts_line (iter))
+ gtk_text_iter_backward_char (iter);
+
+ return TRUE;
+}
+
static gboolean
motion_prev_line (GtkTextIter *iter,
GtkSourceVimMotion *state)
{
guint line = gtk_text_iter_get_line (iter);
- if (line > 0)
- return gtk_text_buffer_get_iter_at_line (gtk_text_iter_get_buffer (iter), iter, line - 1);
-
- if (!gtk_text_iter_is_start (iter))
+ if (line == 0)
{
- gtk_text_iter_set_line_offset (iter, 0);
+ gtk_text_iter_set_offset (iter, 0);
return TRUE;
}
- return FALSE;
+ 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
@@ -1338,6 +1364,28 @@ gtk_source_vim_motion_new_line_end (void)
return GTK_SOURCE_VIM_STATE (self);
}
+GtkSourceVimState *
+gtk_source_vim_motion_new_line_start (void)
+{
+ GtkSourceVimMotion *self;
+
+ self = g_object_new (GTK_SOURCE_TYPE_VIM_MOTION, NULL);
+ self->motion = motion_line_start;
+
+ return GTK_SOURCE_VIM_STATE (self);
+}
+
+GtkSourceVimState *
+gtk_source_vim_motion_new_previous_line_end (void)
+{
+ GtkSourceVimMotion *self;
+
+ self = g_object_new (GTK_SOURCE_TYPE_VIM_MOTION, NULL);
+ self->motion = motion_prev_line_end;
+
+ return GTK_SOURCE_VIM_STATE (self);
+}
+
GtkSourceVimState *
gtk_source_vim_motion_new_none (void)
{
diff --git a/gtksourceview/vim/gtk-source-vim-motion.h b/gtksourceview/vim/gtk-source-vim-motion.h
index 3ba06684..127cad96 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.h
+++ b/gtksourceview/vim/gtk-source-vim-motion.h
@@ -31,13 +31,15 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GtkSourceVimMotion, gtk_source_vim_motion, GTK_SOURCE, VIM_MOTION, GtkSourceVimState)
-GtkSourceVimState *gtk_source_vim_motion_new (void);
-GtkSourceVimState *gtk_source_vim_motion_new_none (void);
-GtkSourceVimState *gtk_source_vim_motion_new_first_char (void);
-GtkSourceVimState *gtk_source_vim_motion_new_line_end (void);
-void gtk_source_vim_motion_set_apply_on_leave (GtkSourceVimMotion *self,
- gboolean apply_on_leave);
-gboolean gtk_source_vim_motion_apply (GtkSourceVimMotion *self,
- GtkTextIter *iter);
+GtkSourceVimState *gtk_source_vim_motion_new (void);
+GtkSourceVimState *gtk_source_vim_motion_new_none (void);
+GtkSourceVimState *gtk_source_vim_motion_new_first_char (void);
+GtkSourceVimState *gtk_source_vim_motion_new_line_end (void);
+GtkSourceVimState *gtk_source_vim_motion_new_previous_line_end (void);
+GtkSourceVimState *gtk_source_vim_motion_new_line_start (void);
+void gtk_source_vim_motion_set_apply_on_leave (GtkSourceVimMotion *self,
+ gboolean apply_on_leave);
+gboolean gtk_source_vim_motion_apply (GtkSourceVimMotion *self,
+ GtkTextIter *iter);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]