[gtksourceview/wip/chergert/vim: 58/73] implement paragraph movements
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 58/73] implement paragraph movements
- Date: Tue, 26 Oct 2021 23:20:37 +0000 (UTC)
commit 16a10aa093c5c80592a62db5b71ae3992772d593
Author: Christian Hergert <chergert redhat com>
Date: Sat Oct 23 16:18:34 2021 -0700
implement paragraph movements
gtksourceview/vim/gtk-source-vim-motion.c | 60 ++++++++++++++++++++++++++++---
gtksourceview/vim/gtk-source-vim-normal.c | 2 ++
2 files changed, 57 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 4405a180..d7f60618 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -59,6 +59,12 @@ struct _GtkSourceVimMotion
G_DEFINE_TYPE (GtkSourceVimMotion, gtk_source_vim_motion, GTK_SOURCE_TYPE_VIM_STATE)
+static gboolean
+line_is_empty (GtkTextIter *iter)
+{
+ return gtk_text_iter_starts_line (iter) && gtk_text_iter_ends_line (iter);
+}
+
enum
{
CLASS_0,
@@ -723,17 +729,61 @@ motion_backward_sentence_start (GtkTextIter *iter,
}
static gboolean
-motion_forward_paragraph_start (GtkTextIter *iter,
- GtkSourceVimMotion *state)
+motion_forward_paragraph_end (GtkTextIter *iter,
+ GtkSourceVimMotion *state)
{
- return FALSE;
+ GtkTextIter before = *iter;
+
+ /* Work our way past the current empty lines */
+ if (line_is_empty (iter))
+ {
+ while (line_is_empty (iter))
+ {
+ if (!gtk_text_iter_forward_line (iter))
+ return FALSE;
+ }
+ }
+
+ /* Now find first line that is empty */
+ while (!line_is_empty (iter))
+ {
+ if (!gtk_text_iter_forward_line (iter))
+ return FALSE;
+ }
+
+ if (gtk_text_iter_is_end (iter) &&
+ !gtk_text_iter_starts_line (iter))
+ {
+ gtk_text_iter_backward_char (iter);
+ }
+
+ return !gtk_text_iter_equal (&before, iter);
}
static gboolean
motion_backward_paragraph_start (GtkTextIter *iter,
GtkSourceVimMotion *state)
{
- return FALSE;
+ GtkTextIter before = *iter;
+
+ /* Work our way past the current empty lines */
+ if (line_is_empty (iter))
+ {
+ while (line_is_empty (iter))
+ {
+ if (!gtk_text_iter_backward_line (iter))
+ return FALSE;
+ }
+ }
+
+ /* Now find first line that is empty */
+ while (!line_is_empty (iter))
+ {
+ if (!gtk_text_iter_backward_line (iter))
+ return FALSE;
+ }
+
+ return !gtk_text_iter_equal (&before, iter);
}
GtkSourceVimState *
@@ -926,7 +976,7 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
return gtk_source_vim_motion_complete (self, motion_backward_paragraph_start);
case GDK_KEY_braceright:
- return gtk_source_vim_motion_complete (self, motion_forward_paragraph_start);
+ return gtk_source_vim_motion_complete (self, motion_forward_paragraph_end);
case GDK_KEY_n:
case GDK_KEY_N:
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index c9362283..d5a06d34 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -401,6 +401,8 @@ key_handler_initial (GtkSourceVimNormal *self,
case GDK_KEY_bar:
case GDK_KEY_B:
case GDK_KEY_BackSpace:
+ case GDK_KEY_braceleft:
+ case GDK_KEY_braceright:
case GDK_KEY_dollar:
case GDK_KEY_Down:
case GDK_KEY_e:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]