diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-08-02 13:54:06 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-08-02 13:54:06 -0400 |
commit | 0add6268224e705f6e3f8f26289846e046098a81 (patch) | |
tree | 1913d374ec3c49aa6065503d24180f0408e44f62 /gtk/gtktextbuffer.c | |
parent | 793ea05f4a30d8b1d36a8fba8be56209eecd5549 (diff) | |
download | gtk+-0add6268224e705f6e3f8f26289846e046098a81.tar.gz |
textbuffer: Be careful with tags when copying
We can only insert tags in the buffer if they come
from the same GtkTextTagTable as the buffer uses.
If that is not the case, paste the text without tags.
Fixes: #2991
Diffstat (limited to 'gtk/gtktextbuffer.c')
-rw-r--r-- | gtk/gtktextbuffer.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c index 3e7e12c0fa..1f616bdce1 100644 --- a/gtk/gtktextbuffer.c +++ b/gtk/gtktextbuffer.c @@ -1605,15 +1605,15 @@ insert_range_not_inside_self (GtkTextBuffer *buffer, GtkTextIter end = *orig_end; GtkTextIter range_start; GtkTextIter range_end; - + if (gtk_text_iter_equal (orig_start, orig_end)) return; - + gtk_text_iter_order (&start, &end); range_start = start; - range_end = start; - + range_end = start; + while (TRUE) { int start_offset; @@ -1621,12 +1621,12 @@ insert_range_not_inside_self (GtkTextBuffer *buffer, GSList *tags; GSList *tmp_list; Range *r; - + if (gtk_text_iter_equal (&range_start, &end)) break; /* All done */ g_assert (gtk_text_iter_compare (&range_start, &end) < 0); - + gtk_text_iter_forward_to_tag_toggle (&range_end, NULL); g_assert (!gtk_text_iter_equal (&range_start, &range_end)); @@ -1634,33 +1634,32 @@ insert_range_not_inside_self (GtkTextBuffer *buffer, /* Clamp to the end iterator */ if (gtk_text_iter_compare (&range_end, &end) > 0) range_end = end; - + /* We have a range with unique tags; insert it, and * apply all tags. */ start_offset = gtk_text_iter_get_offset (iter); r = save_range (&range_start, &range_end, &end); - + insert_range_untagged (buffer, iter, &range_start, &range_end, interactive); restore_range (r); r = NULL; - - gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start_offset); - - tags = gtk_text_iter_get_tags (&range_start); - tmp_list = tags; - while (tmp_list != NULL) + + if (gtk_text_buffer_get_tag_table (gtk_text_iter_get_buffer (orig_start)) == gtk_text_buffer_get_tag_table (buffer)) { - gtk_text_buffer_apply_tag (buffer, - tmp_list->data, - &start_iter, - iter); + gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start_offset); - tmp_list = tmp_list->next; + tags = gtk_text_iter_get_tags (&range_start); + tmp_list = tags; + while (tmp_list != NULL) + { + gtk_text_buffer_apply_tag (buffer, tmp_list->data, &start_iter, iter); + tmp_list = tmp_list->next; + } + g_slist_free (tags); } - g_slist_free (tags); range_start = range_end; } |