[gtksourceview/wip/chergert/vim] improve extending text-object for word/WORD
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] improve extending text-object for word/WORD
- Date: Fri, 5 Nov 2021 04:49:32 +0000 (UTC)
commit 9aff99aa85c4d2314ea5873fd756646f0e87ffe4
Author: Christian Hergert <chergert redhat com>
Date: Thu Nov 4 21:49:26 2021 -0700
improve extending text-object for word/WORD
gtksourceview/vim/gtk-source-vim-text-object.c | 36 ++++++++++++++++----------
testsuite/test-vim-text-object.c | 2 +-
2 files changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-text-object.c b/gtksourceview/vim/gtk-source-vim-text-object.c
index 2afe5f10..502e8a65 100644
--- a/gtksourceview/vim/gtk-source-vim-text-object.c
+++ b/gtksourceview/vim/gtk-source-vim-text-object.c
@@ -68,6 +68,20 @@ backward_to_first_space (GtkTextIter *iter)
}
}
+static void
+forward_to_nonspace (GtkTextIter *iter)
+{
+ while (!gtk_text_iter_ends_line (iter))
+ {
+ if (!iter_isspace (iter))
+ {
+ break;
+ }
+
+ gtk_text_iter_forward_char (iter);
+ }
+}
+
static void
text_object_extend_word (const GtkTextIter *origin,
GtkTextIter *inner_begin,
@@ -77,23 +91,19 @@ text_object_extend_word (const GtkTextIter *origin,
{
gtk_text_iter_forward_char (inner_end);
- *a_begin = *inner_begin;
- *a_end = *inner_end;
-
- while (!gtk_text_iter_ends_line (a_end) && iter_isspace (a_end))
- gtk_text_iter_forward_char (a_end);
-
- backward_to_first_space (a_begin);
-
- /* If @origin is between a_begin and inner_begin, then we
- * actually want to just select that space.
- */
- if (gtk_text_iter_compare (a_begin, origin) <= 0 &&
- gtk_text_iter_compare (origin, inner_begin) < 0)
+ if (gtk_text_iter_compare (origin, inner_begin) < 0)
{
+ *a_begin = *inner_begin;
+ *a_end = *inner_end;
+ backward_to_first_space (a_begin);
*inner_end = *inner_begin;
*inner_begin = *a_begin;
+ }
+ else
+ {
+ *a_begin = *inner_begin;
*a_end = *inner_end;
+ forward_to_nonspace (a_end);
}
}
diff --git a/testsuite/test-vim-text-object.c b/testsuite/test-vim-text-object.c
index e9f585a8..031f58fc 100644
--- a/testsuite/test-vim-text-object.c
+++ b/testsuite/test-vim-text-object.c
@@ -78,7 +78,7 @@ test_word (void)
run_test (gtk_source_vim_text_object_new_inner_word (), "something here", 9, " ", FALSE);
run_test (gtk_source_vim_text_object_new_inner_word (), "a", 0, "a", FALSE);
run_test (gtk_source_vim_text_object_new_inner_word (), "a b", 1, " ", FALSE);
- //run_test (gtk_source_vim_text_object_new_a_word (), "a b", 1, " b", FALSE);
+ run_test (gtk_source_vim_text_object_new_a_word (), "a b", 1, " b", FALSE);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]