mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-23 20:30:15 +00:00
Fix gtk_text_iter_forward_to_tag_toggle() for end iter
The function must return TRUE only if there is a tag toggle _after_ the iter, not _at_ the iter. So for the end iter, the function must always return FALSE. Add also unit tests for gtk_text_iter_forward_to_tag_toggle(). https://bugzilla.gnome.org/show_bug.cgi?id=691266
This commit is contained in:
parent
555e0a785d
commit
08d49fdd58
@ -4163,6 +4163,9 @@ gtk_text_iter_forward_to_tag_toggle (GtkTextIter *iter,
|
||||
|
||||
check_invariants (iter);
|
||||
|
||||
if (gtk_text_iter_is_end (iter))
|
||||
return FALSE;
|
||||
|
||||
current_line = real->line;
|
||||
next_line = _gtk_text_line_next_could_contain_tag (current_line,
|
||||
real->tree, tag);
|
||||
|
@ -255,6 +255,57 @@ test_search_caseless (void)
|
||||
check_found_backward ("This is some \303\200\n\303\200 text", "a\314\200\na\314\200", flags, 13, 16, "\303\200\n\303\200");
|
||||
}
|
||||
|
||||
static void
|
||||
test_forward_to_tag_toggle (void)
|
||||
{
|
||||
GtkTextBuffer *buffer;
|
||||
GtkTextTag *bold_tag;
|
||||
GtkTextTag *editable_tag;
|
||||
GtkTextIter iter;
|
||||
gint offset;
|
||||
|
||||
buffer = gtk_text_buffer_new (NULL);
|
||||
|
||||
bold_tag = gtk_text_buffer_create_tag (buffer, "bold",
|
||||
"weight", PANGO_WEIGHT_BOLD,
|
||||
NULL);
|
||||
|
||||
editable_tag = gtk_text_buffer_create_tag (buffer, "not-editable",
|
||||
"editable", FALSE,
|
||||
NULL);
|
||||
|
||||
gtk_text_buffer_get_start_iter (buffer, &iter);
|
||||
|
||||
gtk_text_buffer_insert (buffer, &iter, "a", -1);
|
||||
gtk_text_buffer_insert_with_tags (buffer, &iter, "b", -1, bold_tag, NULL);
|
||||
gtk_text_buffer_insert_with_tags (buffer, &iter, "c", -1, editable_tag, NULL);
|
||||
|
||||
/* Go to the first "on" toggle */
|
||||
gtk_text_buffer_get_start_iter (buffer, &iter);
|
||||
g_assert (gtk_text_iter_forward_to_tag_toggle (&iter, NULL));
|
||||
offset = gtk_text_iter_get_offset (&iter);
|
||||
g_assert_cmpint (offset, ==, 1);
|
||||
|
||||
/* Go to the last "off" toggle for the bold tag */
|
||||
g_assert (gtk_text_iter_forward_to_tag_toggle (&iter, bold_tag));
|
||||
offset = gtk_text_iter_get_offset (&iter);
|
||||
g_assert_cmpint (offset, ==, 2);
|
||||
|
||||
g_assert (!gtk_text_iter_forward_to_tag_toggle (&iter, bold_tag));
|
||||
|
||||
/* Go to the first "on" toggle for the editable tag */
|
||||
gtk_text_buffer_get_start_iter (buffer, &iter);
|
||||
g_assert (gtk_text_iter_forward_to_tag_toggle (&iter, editable_tag));
|
||||
offset = gtk_text_iter_get_offset (&iter);
|
||||
g_assert_cmpint (offset, ==, 2);
|
||||
|
||||
/* Test with the end iter */
|
||||
gtk_text_buffer_get_end_iter (buffer, &iter);
|
||||
g_assert (!gtk_text_iter_forward_to_tag_toggle (&iter, editable_tag));
|
||||
|
||||
g_object_unref (buffer);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char** argv)
|
||||
{
|
||||
@ -264,6 +315,7 @@ main (int argc, char** argv)
|
||||
g_test_add_func ("/TextIter/Search Full Buffer", test_full_buffer);
|
||||
g_test_add_func ("/TextIter/Search", test_search);
|
||||
g_test_add_func ("/TextIter/Search Caseless", test_search_caseless);
|
||||
g_test_add_func ("/TextIter/Forward To Tag Toggle", test_forward_to_tag_toggle);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user