[gtksourceview/gnome-3-22] Fix gtk_source_buffer_sort_lines()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gnome-3-22] Fix gtk_source_buffer_sort_lines()
- Date: Fri, 30 Sep 2016 12:30:15 +0000 (UTC)
commit 4b4e9ee6e8d9e596dd443bb6cb2f7012d1b66a09
Author: Garrett Regier <garrettregier gmail com>
Date: Tue Sep 13 09:40:31 2016 -0700
Fix gtk_source_buffer_sort_lines()
The start iterator needs to be moved to the
start of the line for gtk_text_iter_delete().
Also, return early if the start and end iter
are on the same line.
https://bugzilla.gnome.org/show_bug.cgi?id=771373
gtksourceview/gtksourcebuffer.c | 13 ++++++++++++-
testsuite/test-buffer.c | 6 ++++++
2 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 13260e7..a053352 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2939,10 +2939,16 @@ gtk_source_buffer_sort_lines (GtkSourceBuffer *buffer,
start_line = gtk_text_iter_get_line (start);
end_line = gtk_text_iter_get_line (end);
+ /* Required for gtk_text_buffer_delete() */
+ if (!gtk_text_iter_starts_line (start))
+ {
+ gtk_text_iter_set_line_offset (start, 0);
+ }
+
/* if we are at line start our last line is the previus one.
* Otherwise the last line is the current one but we try to
* move the iter after the line terminator */
- if (gtk_text_iter_get_line_offset (end) == 0)
+ if (gtk_text_iter_starts_line (end))
{
end_line = MAX (start_line, end_line - 1);
}
@@ -2951,6 +2957,11 @@ gtk_source_buffer_sort_lines (GtkSourceBuffer *buffer,
gtk_text_iter_forward_line (end);
}
+ if (start_line == end_line)
+ {
+ return;
+ }
+
num_lines = end_line - start_line + 1;
lines = g_new0 (SortLine, num_lines);
diff --git a/testsuite/test-buffer.c b/testsuite/test-buffer.c
index 59d1597..7a723c2 100644
--- a/testsuite/test-buffer.c
+++ b/testsuite/test-buffer.c
@@ -280,10 +280,16 @@ test_sort_lines (void)
do_test_sort_lines (buffer, "aaa\nbbb\n", "aaa\nbbb\n", 0, -1, 0, 0);
do_test_sort_lines (buffer, "bbb\naaa\n", "aaa\nbbb\n", 0, -1, 0, 0);
+ do_test_sort_lines (buffer, "bbb\naaa\n", "aaa\nbbb\n", 1, -1, 0, 0);
+ do_test_sort_lines (buffer, "bbb\naaa\n", "aaa\nbbb\n", 0, 5, 0, 0);
+ do_test_sort_lines (buffer, "ccc\nbbb\naaa\n", "bbb\nccc\naaa\n", 0, 7, 0, 0);
+ do_test_sort_lines (buffer, "ccc\nbbb\naaa\n", "bbb\nccc\naaa\n", 0, 8, 0, 0);
+ do_test_sort_lines (buffer, "ccc\nbbb\naaa\n", "aaa\nbbb\nccc\n", 0, 9, 0, 0);
do_test_sort_lines (buffer, "aaa\nbbb\n", "bbb\naaa\n", 0, -1, GTK_SOURCE_SORT_FLAGS_REVERSE_ORDER,
0);
do_test_sort_lines (buffer, "aaa\nbbb\naaa\n", "aaa\nbbb\n", 0, -1,
GTK_SOURCE_SORT_FLAGS_REMOVE_DUPLICATES, 0);
do_test_sort_lines (buffer, "bbb\naaa\nCCC\n", "CCC\naaa\nbbb\n", 0, -1,
GTK_SOURCE_SORT_FLAGS_CASE_SENSITIVE, 0);
do_test_sort_lines (buffer, "aaabbb\nbbbaaa\n", "bbbaaa\naaabbb\n", 0, -1, 0, 3);
+ do_test_sort_lines (buffer, "abcdefghijk\n", "abcdefghijk\n", 2, 6, 0, 0);
g_object_unref (buffer);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]