[gtksourceview/wip/chergert/vim] fix another fun paragraph boundary issue
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] fix another fun paragraph boundary issue
- Date: Fri, 5 Nov 2021 21:52:45 +0000 (UTC)
commit b112c956fb0ce4ec7bf36c3fd3c70dd83974c3ad
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 5 14:52:35 2021 -0700
fix another fun paragraph boundary issue
gtksourceview/vim/gtk-source-vim-text-object.c | 20 +++++++++++++++++---
testsuite/test-vim-text-object.c | 1 +
2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-text-object.c b/gtksourceview/vim/gtk-source-vim-text-object.c
index 15b4e35e..49e26972 100644
--- a/gtksourceview/vim/gtk-source-vim-text-object.c
+++ b/gtksourceview/vim/gtk-source-vim-text-object.c
@@ -294,6 +294,9 @@ text_object_extend_paragraph (const GtkTextIter *origin,
GtkTextIter *a_end)
{
GtkTextIter next;
+ gboolean started_on_empty;
+
+ started_on_empty = is_empty_line (inner_begin);
if (is_empty_line (a_begin))
{
@@ -331,11 +334,22 @@ text_object_extend_paragraph (const GtkTextIter *origin,
break;
}
- if (is_empty_line (inner_begin))
+ if (started_on_empty)
+ {
*inner_begin = *a_begin;
-
- if (is_empty_line (inner_end))
*inner_end = *a_end;
+
+ /* If the original position is empty, then `ap` should
+ * place @a_end at the end of the next found paragraph.
+ */
+ next = *a_end;
+ gtk_text_iter_forward_line (&next);
+ while (!is_empty_line (&next) && !gtk_text_iter_is_end (&next))
+ gtk_text_iter_forward_line (&next);
+ if (gtk_text_iter_compare (&next, a_end) > 0)
+ gtk_text_iter_backward_char (&next);
+ *a_end = next;
+ }
}
static void
diff --git a/testsuite/test-vim-text-object.c b/testsuite/test-vim-text-object.c
index 9f06f650..bb597984 100644
--- a/testsuite/test-vim-text-object.c
+++ b/testsuite/test-vim-text-object.c
@@ -199,6 +199,7 @@ test_paragraph (void)
run_test (gtk_source_vim_text_object_new_a_paragraph (), "\n\n\n", 1, "\n\n\n");
run_test (gtk_source_vim_text_object_new_a_paragraph (), "what\nwill\n we\n\nfind\nhere.", 1,
"what\nwill\n we\n");
run_test (gtk_source_vim_text_object_new_a_paragraph (), "\tword;\n\n\tanother;\n\n\tthird;\n", 9,
"\tanother;\n");
+ run_test (gtk_source_vim_text_object_new_a_paragraph (), "\tword;\n\n\tanother;\n", 7,
"\n\tanother;");
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]