[gtksourceview/wip/chergert/vim: 54/293] work on word movements
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 54/293] work on word movements
- Date: Fri, 5 Nov 2021 04:22:57 +0000 (UTC)
commit a5de31c001bd2043d5baa06b4a8a01ff8b10b63b
Author: Christian Hergert <chergert redhat com>
Date: Sat Oct 23 13:05:39 2021 -0700
work on word movements
still wrong for b/B but getting closer
gtksourceview/vim/gtk-source-vim-motion.c | 79 ++++++++++++++++++++-----------
1 file changed, 52 insertions(+), 27 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index ab5a33ce..072b5271 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -63,7 +63,8 @@ enum
};
static int
-classify_word (gunichar ch)
+classify_word (gunichar ch,
+ const GtkTextIter *iter)
{
switch (ch)
{
@@ -90,16 +91,40 @@ classify_word (gunichar ch)
}
static int
-classify_WORD (gunichar ch)
+classify_word_newline_stop (gunichar ch,
+ const GtkTextIter *iter)
+{
+ if (gtk_text_iter_starts_line (iter) &&
+ gtk_text_iter_ends_line (iter))
+ return CLASS_NEWLINE;
+
+ return classify_word (ch, iter);
+}
+
+static int
+classify_WORD (gunichar ch,
+ const GtkTextIter *iter)
{
if (g_unichar_isspace (ch))
return CLASS_SPACE;
+
return CLASS_WORD;
}
+static int
+classify_WORD_newline_stop (gunichar ch,
+ const GtkTextIter *iter)
+{
+ if (gtk_text_iter_starts_line (iter) &&
+ gtk_text_iter_ends_line (iter))
+ return CLASS_NEWLINE;
+
+ return classify_WORD (ch, iter);
+}
+
static gboolean
forward_classified_start (GtkTextIter *iter,
- gint (*classify) (gunichar))
+ int (*classify) (gunichar, const GtkTextIter *))
{
gint begin_class;
gint cur_class;
@@ -108,7 +133,7 @@ forward_classified_start (GtkTextIter *iter,
g_assert (iter);
ch = gtk_text_iter_get_char (iter);
- begin_class = classify (ch);
+ begin_class = classify (ch, iter);
/* Move to the first non-whitespace character if necessary. */
if (begin_class == CLASS_SPACE)
@@ -119,7 +144,7 @@ forward_classified_start (GtkTextIter *iter,
return FALSE;
ch = gtk_text_iter_get_char (iter);
- cur_class = classify (ch);
+ cur_class = classify (ch, iter);
if (cur_class != CLASS_SPACE)
return TRUE;
}
@@ -129,7 +154,7 @@ forward_classified_start (GtkTextIter *iter,
while (gtk_text_iter_forward_char (iter))
{
ch = gtk_text_iter_get_char (iter);
- cur_class = classify (ch);
+ cur_class = classify (ch, iter);
if (cur_class == CLASS_SPACE)
{
@@ -146,7 +171,7 @@ forward_classified_start (GtkTextIter *iter,
static gboolean
forward_classified_end (GtkTextIter *iter,
- gint (*classify) (gunichar))
+ int (*classify) (gunichar, const GtkTextIter *))
{
gunichar ch;
gint begin_class;
@@ -159,12 +184,12 @@ forward_classified_end (GtkTextIter *iter,
/* If we are on space, walk to the start of the next word. */
ch = gtk_text_iter_get_char (iter);
- if (classify (ch) == CLASS_SPACE)
+ if (classify (ch, iter) == CLASS_SPACE)
if (!forward_classified_start (iter, classify))
return FALSE;
ch = gtk_text_iter_get_char (iter);
- begin_class = classify (ch);
+ begin_class = classify (ch, iter);
if (begin_class == CLASS_NEWLINE)
{
@@ -178,7 +203,7 @@ forward_classified_end (GtkTextIter *iter,
return FALSE;
ch = gtk_text_iter_get_char (iter);
- cur_class = classify (ch);
+ cur_class = classify (ch, iter);
if (cur_class != begin_class || cur_class == CLASS_NEWLINE)
{
@@ -192,7 +217,7 @@ forward_classified_end (GtkTextIter *iter,
static gboolean
backward_classified_end (GtkTextIter *iter,
- gint (*classify) (gunichar))
+ int (*classify) (gunichar, const GtkTextIter *))
{
gunichar ch;
gint begin_class;
@@ -201,7 +226,7 @@ backward_classified_end (GtkTextIter *iter,
g_assert (iter);
ch = gtk_text_iter_get_char (iter);
- begin_class = classify (ch);
+ begin_class = classify (ch, iter);
if (begin_class == CLASS_NEWLINE)
{
@@ -215,7 +240,7 @@ backward_classified_end (GtkTextIter *iter,
return FALSE;
ch = gtk_text_iter_get_char (iter);
- cur_class = classify (ch);
+ cur_class = classify (ch, iter);
if (cur_class == CLASS_NEWLINE)
{
@@ -236,7 +261,7 @@ backward_classified_end (GtkTextIter *iter,
static gboolean
backward_classified_start (GtkTextIter *iter,
- gint (*classify) (gunichar))
+ int (*classify) (gunichar, const GtkTextIter *))
{
gunichar ch;
gint begin_class;
@@ -249,12 +274,12 @@ backward_classified_start (GtkTextIter *iter,
/* If we are on space, walk to the end of the previous word. */
ch = gtk_text_iter_get_char (iter);
- if (classify (ch) == CLASS_SPACE)
+ if (classify (ch, iter) == CLASS_SPACE)
if (!backward_classified_end (iter, classify))
return FALSE;
ch = gtk_text_iter_get_char (iter);
- begin_class = classify (ch);
+ begin_class = classify (ch, iter);
if (begin_class == CLASS_NEWLINE)
{
gtk_text_iter_forward_char (iter);
@@ -267,7 +292,7 @@ backward_classified_start (GtkTextIter *iter,
return FALSE;
ch = gtk_text_iter_get_char (iter);
- cur_class = classify (ch);
+ cur_class = classify (ch, iter);
if (cur_class != begin_class || cur_class == CLASS_NEWLINE)
{
@@ -522,56 +547,56 @@ static gboolean
motion_forward_word_start (GtkTextIter *iter,
GtkSourceView *view)
{
- return forward_classified_start (iter, classify_word);
+ return forward_classified_start (iter, classify_word_newline_stop);
}
static gboolean
motion_forward_WORD_start (GtkTextIter *iter,
GtkSourceView *view)
{
- return forward_classified_start (iter, classify_WORD);
+ return forward_classified_start (iter, classify_WORD_newline_stop);
}
static gboolean
motion_forward_word_end (GtkTextIter *iter,
GtkSourceView *view)
{
- return forward_classified_end (iter, classify_word);
+ return forward_classified_end (iter, classify_word_newline_stop);
}
static gboolean
motion_forward_WORD_end (GtkTextIter *iter,
GtkSourceView *view)
{
- return forward_classified_end (iter, classify_WORD);
+ return forward_classified_end (iter, classify_WORD_newline_stop);
}
static gboolean
motion_backward_word_start (GtkTextIter *iter,
- GtkSourceView *view)
+ GtkSourceView *view)
{
- return backward_classified_start (iter, classify_word);
+ return backward_classified_start (iter, classify_word_newline_stop);
}
static gboolean
motion_backward_WORD_start (GtkTextIter *iter,
- GtkSourceView *view)
+ GtkSourceView *view)
{
- return backward_classified_start (iter, classify_WORD);
+ return backward_classified_start (iter, classify_WORD_newline_stop);
}
static gboolean
motion_backward_word_end (GtkTextIter *iter,
GtkSourceView *view)
{
- return backward_classified_end (iter, classify_word);
+ return backward_classified_end (iter, classify_word_newline_stop);
}
static gboolean
motion_backward_WORD_end (GtkTextIter *iter,
GtkSourceView *view)
{
- return backward_classified_end (iter, classify_WORD);
+ return backward_classified_end (iter, classify_WORD_newline_stop);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]