Merge branch 'matthiasc/for-main' into 'main'

textbuffer: Fix pasting text

Closes #4357

See merge request GNOME/gtk!4205
This commit is contained in:
Matthias Clasen 2021-12-01 02:59:10 +00:00
commit 2611a996ff

View File

@ -296,7 +296,7 @@ gtk_text_buffer_content_new (GtkTextBuffer *buffer)
content = g_object_new (GTK_TYPE_TEXT_BUFFER_CONTENT, NULL); content = g_object_new (GTK_TYPE_TEXT_BUFFER_CONTENT, NULL);
content->text_buffer = g_object_ref (buffer); content->text_buffer = g_object_ref (buffer);
return GDK_CONTENT_PROVIDER (content); return GDK_CONTENT_PROVIDER (content);
} }
@ -310,6 +310,7 @@ gtk_text_buffer_deserialize_text_plain_finish (GObject *source,
GtkTextIter start, end; GtkTextIter start, end;
GError *error = NULL; GError *error = NULL;
gssize written; gssize written;
gsize size;
char *data; char *data;
written = g_output_stream_splice_finish (stream, result, &error); written = g_output_stream_splice_finish (stream, result, &error);
@ -319,14 +320,18 @@ gtk_text_buffer_deserialize_text_plain_finish (GObject *source,
return; return;
} }
size = g_memory_output_stream_get_size (G_MEMORY_OUTPUT_STREAM (
g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (stream))));
data = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM ( data = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (
g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (stream)))); g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (stream))));
if (data) if (data)
{ {
if (memchr (data, '\0', size))
size = -1;
buffer = g_value_get_object (gdk_content_deserializer_get_value (deserializer)); buffer = g_value_get_object (gdk_content_deserializer_get_value (deserializer));
gtk_text_buffer_get_end_iter (buffer, &end); gtk_text_buffer_get_end_iter (buffer, &end);
gtk_text_buffer_insert (buffer, &end, data, -1); gtk_text_buffer_insert (buffer, &end, data, size);
gtk_text_buffer_get_bounds (buffer, &start, &end); gtk_text_buffer_get_bounds (buffer, &start, &end);
gtk_text_buffer_select_range (buffer, &start, &end); gtk_text_buffer_select_range (buffer, &start, &end);
@ -437,7 +442,7 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass)
object_class->finalize = gtk_text_buffer_finalize; object_class->finalize = gtk_text_buffer_finalize;
object_class->set_property = gtk_text_buffer_set_property; object_class->set_property = gtk_text_buffer_set_property;
object_class->get_property = gtk_text_buffer_get_property; object_class->get_property = gtk_text_buffer_get_property;
klass->insert_text = gtk_text_buffer_real_insert_text; klass->insert_text = gtk_text_buffer_real_insert_text;
klass->insert_paintable = gtk_text_buffer_real_insert_paintable; klass->insert_paintable = gtk_text_buffer_real_insert_paintable;
klass->insert_child_anchor = gtk_text_buffer_real_insert_anchor; klass->insert_child_anchor = gtk_text_buffer_real_insert_anchor;
@ -643,15 +648,15 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass)
g_signal_set_va_marshaller (signals[INSERT_CHILD_ANCHOR], g_signal_set_va_marshaller (signals[INSERT_CHILD_ANCHOR],
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
_gtk_marshal_VOID__BOXED_OBJECTv); _gtk_marshal_VOID__BOXED_OBJECTv);
/** /**
* GtkTextBuffer::delete-range: * GtkTextBuffer::delete-range:
* @textbuffer: the object which received the signal * @textbuffer: the object which received the signal
* @start: the start of the range to be deleted * @start: the start of the range to be deleted
* @end: the end of the range to be deleted * @end: the end of the range to be deleted
* *
* Emitted to delete a range from a `GtkTextBuffer`. * Emitted to delete a range from a `GtkTextBuffer`.
* *
* Note that if your handler runs before the default handler * Note that if your handler runs before the default handler
* it must not invalidate the @start and @end iters (or has * it must not invalidate the @start and @end iters (or has
* to revalidate them). The default signal handler revalidates * to revalidate them). The default signal handler revalidates
@ -846,7 +851,7 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass)
signals[BEGIN_USER_ACTION] = signals[BEGIN_USER_ACTION] =
g_signal_new (I_("begin-user-action"), g_signal_new (I_("begin-user-action"),
G_OBJECT_CLASS_TYPE (object_class), G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkTextBufferClass, begin_user_action), G_STRUCT_OFFSET (GtkTextBufferClass, begin_user_action),
NULL, NULL, NULL, NULL,
NULL, NULL,
@ -872,7 +877,7 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass)
signals[END_USER_ACTION] = signals[END_USER_ACTION] =
g_signal_new (I_("end-user-action"), g_signal_new (I_("end-user-action"),
G_OBJECT_CLASS_TYPE (object_class), G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkTextBufferClass, end_user_action), G_STRUCT_OFFSET (GtkTextBufferClass, end_user_action),
NULL, NULL, NULL, NULL,
NULL, NULL,
@ -1042,7 +1047,7 @@ gtk_text_buffer_get_property (GObject *object,
break; break;
case PROP_CURSOR_POSITION: case PROP_CURSOR_POSITION:
gtk_text_buffer_get_iter_at_mark (text_buffer, &iter, gtk_text_buffer_get_iter_at_mark (text_buffer, &iter,
gtk_text_buffer_get_insert (text_buffer)); gtk_text_buffer_get_insert (text_buffer));
g_value_set_int (value, gtk_text_iter_get_offset (&iter)); g_value_set_int (value, gtk_text_iter_get_offset (&iter));
break; break;
@ -1198,7 +1203,7 @@ gtk_text_buffer_real_insert_text (GtkTextBuffer *buffer,
{ {
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
g_return_if_fail (iter != NULL); g_return_if_fail (iter != NULL);
gtk_text_history_text_inserted (buffer->priv->history, gtk_text_history_text_inserted (buffer->priv->history,
gtk_text_iter_get_offset (iter), gtk_text_iter_get_offset (iter),
text, text,
@ -1224,7 +1229,7 @@ gtk_text_buffer_emit_insert (GtkTextBuffer *buffer,
len = strlen (text); len = strlen (text);
g_return_if_fail (g_utf8_validate (text, len, NULL)); g_return_if_fail (g_utf8_validate (text, len, NULL));
if (len > 0) if (len > 0)
{ {
g_signal_emit (buffer, signals[INSERT_TEXT], 0, g_signal_emit (buffer, signals[INSERT_TEXT], 0,
@ -1258,7 +1263,7 @@ gtk_text_buffer_insert (GtkTextBuffer *buffer,
g_return_if_fail (iter != NULL); g_return_if_fail (iter != NULL);
g_return_if_fail (text != NULL); g_return_if_fail (text != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
gtk_text_buffer_emit_insert (buffer, iter, text, len); gtk_text_buffer_emit_insert (buffer, iter, text, len);
} }
@ -1414,19 +1419,19 @@ save_range (GtkTextIter *range_start,
r->buffer = gtk_text_iter_get_buffer (range_start); r->buffer = gtk_text_iter_get_buffer (range_start);
g_object_ref (r->buffer); g_object_ref (r->buffer);
r->start_mark = r->start_mark =
gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start), gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start),
NULL, NULL,
range_start, range_start,
FALSE); FALSE);
r->end_mark = r->end_mark =
gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start), gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start),
NULL, NULL,
range_end, range_end,
TRUE); TRUE);
r->whole_end_mark = r->whole_end_mark =
gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start), gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start),
NULL, NULL,
whole_end, whole_end,
@ -1445,15 +1450,15 @@ restore_range (Range *r)
gtk_text_buffer_get_iter_at_mark (r->buffer, gtk_text_buffer_get_iter_at_mark (r->buffer,
r->range_start, r->range_start,
r->start_mark); r->start_mark);
gtk_text_buffer_get_iter_at_mark (r->buffer, gtk_text_buffer_get_iter_at_mark (r->buffer,
r->range_end, r->range_end,
r->end_mark); r->end_mark);
gtk_text_buffer_get_iter_at_mark (r->buffer, gtk_text_buffer_get_iter_at_mark (r->buffer,
r->whole_end, r->whole_end,
r->whole_end_mark); r->whole_end_mark);
gtk_text_buffer_delete_mark (r->buffer, r->start_mark); gtk_text_buffer_delete_mark (r->buffer, r->start_mark);
gtk_text_buffer_delete_mark (r->buffer, r->end_mark); gtk_text_buffer_delete_mark (r->buffer, r->end_mark);
gtk_text_buffer_delete_mark (r->buffer, r->whole_end_mark); gtk_text_buffer_delete_mark (r->buffer, r->whole_end_mark);
@ -1462,13 +1467,13 @@ restore_range (Range *r)
* gotten mangled; we switch to an empty range in that * gotten mangled; we switch to an empty range in that
* case * case
*/ */
if (gtk_text_iter_compare (r->range_start, r->range_end) > 0) if (gtk_text_iter_compare (r->range_start, r->range_end) > 0)
*r->range_start = *r->range_end; *r->range_start = *r->range_end;
if (gtk_text_iter_compare (r->range_end, r->whole_end) > 0) if (gtk_text_iter_compare (r->range_end, r->whole_end) > 0)
*r->range_end = *r->whole_end; *r->range_end = *r->whole_end;
g_object_unref (r->buffer); g_object_unref (r->buffer);
g_slice_free (Range, r); g_slice_free (Range, r);
} }
@ -1484,16 +1489,16 @@ insert_range_untagged (GtkTextBuffer *buffer,
GtkTextIter range_end; GtkTextIter range_end;
GtkTextIter start, end; GtkTextIter start, end;
Range *r; Range *r;
if (gtk_text_iter_equal (orig_start, orig_end)) if (gtk_text_iter_equal (orig_start, orig_end))
return; return;
start = *orig_start; start = *orig_start;
end = *orig_end; end = *orig_end;
range_start = start; range_start = start;
range_end = start; range_end = start;
while (TRUE) while (TRUE)
{ {
if (gtk_text_iter_equal (&range_start, &range_end)) if (gtk_text_iter_equal (&range_start, &range_end))
@ -1501,7 +1506,7 @@ insert_range_untagged (GtkTextBuffer *buffer,
/* Figure out how to move forward */ /* Figure out how to move forward */
g_assert (gtk_text_iter_compare (&range_end, &end) <= 0); g_assert (gtk_text_iter_compare (&range_end, &end) <= 0);
if (gtk_text_iter_equal (&range_end, &end)) if (gtk_text_iter_equal (&range_end, &end))
{ {
/* nothing left to do */ /* nothing left to do */
@ -1540,12 +1545,12 @@ insert_range_untagged (GtkTextBuffer *buffer,
else else
{ {
/* The GTK_TEXT_UNKNOWN_CHAR was in a text segment, so /* The GTK_TEXT_UNKNOWN_CHAR was in a text segment, so
* keep going. * keep going.
*/ */
gtk_text_iter_forward_find_char (&range_end, gtk_text_iter_forward_find_char (&range_end,
possibly_not_text, NULL, possibly_not_text, NULL,
&end); &end);
g_assert (gtk_text_iter_compare (&range_end, &end) <= 0); g_assert (gtk_text_iter_compare (&range_end, &end) <= 0);
} }
} }
@ -1557,7 +1562,7 @@ insert_range_untagged (GtkTextBuffer *buffer,
gtk_text_iter_forward_find_char (&range_end, gtk_text_iter_forward_find_char (&range_end,
possibly_not_text, NULL, possibly_not_text, NULL,
&end); &end);
g_assert (gtk_text_iter_compare (&range_end, &end) <= 0); g_assert (gtk_text_iter_compare (&range_end, &end) <= 0);
} }
} }
@ -1566,7 +1571,7 @@ insert_range_untagged (GtkTextBuffer *buffer,
r = save_range (&range_start, r = save_range (&range_start,
&range_end, &range_end,
&end); &end);
insert_text_range (buffer, insert_text_range (buffer,
iter, iter,
&range_start, &range_start,
@ -1575,7 +1580,7 @@ insert_range_untagged (GtkTextBuffer *buffer,
restore_range (r); restore_range (r);
r = NULL; r = NULL;
range_start = range_end; range_start = range_end;
} }
} }
@ -1667,18 +1672,18 @@ gtk_text_buffer_real_insert_range (GtkTextBuffer *buffer,
gboolean interactive) gboolean interactive)
{ {
GtkTextBuffer *src_buffer; GtkTextBuffer *src_buffer;
/* Find each range of uniformly-tagged text, insert it, /* Find each range of uniformly-tagged text, insert it,
* then apply the tags. * then apply the tags.
*/ */
if (gtk_text_iter_equal (orig_start, orig_end)) if (gtk_text_iter_equal (orig_start, orig_end))
return; return;
if (interactive) if (interactive)
gtk_text_buffer_begin_user_action (buffer); gtk_text_buffer_begin_user_action (buffer);
src_buffer = gtk_text_iter_get_buffer (orig_start); src_buffer = gtk_text_iter_get_buffer (orig_start);
if (gtk_text_iter_get_buffer (iter) != src_buffer || if (gtk_text_iter_get_buffer (iter) != src_buffer ||
!gtk_text_iter_in_range (iter, orig_start, orig_end)) !gtk_text_iter_in_range (iter, orig_start, orig_end))
{ {
@ -1699,7 +1704,7 @@ gtk_text_buffer_real_insert_range (GtkTextBuffer *buffer,
Range *second_half; Range *second_half;
gtk_text_iter_order (&start, &end); gtk_text_iter_order (&start, &end);
range_start = start; range_start = start;
range_end = *iter; range_end = *iter;
first_half = save_range (&range_start, &range_end, &end); first_half = save_range (&range_start, &range_end, &end);
@ -1714,7 +1719,7 @@ gtk_text_buffer_real_insert_range (GtkTextBuffer *buffer,
restore_range (second_half); restore_range (second_half);
insert_range_not_inside_self (buffer, iter, &range_start, &range_end, interactive); insert_range_not_inside_self (buffer, iter, &range_start, &range_end, interactive);
} }
if (interactive) if (interactive)
gtk_text_buffer_end_user_action (buffer); gtk_text_buffer_end_user_action (buffer);
} }
@ -1753,7 +1758,7 @@ gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
g_return_if_fail (gtk_text_iter_get_buffer (start)->priv->tag_table == g_return_if_fail (gtk_text_iter_get_buffer (start)->priv->tag_table ==
buffer->priv->tag_table); buffer->priv->tag_table);
g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
gtk_text_buffer_real_insert_range (buffer, iter, start, end, FALSE); gtk_text_buffer_real_insert_range (buffer, iter, start, end, FALSE);
} }
@ -1889,7 +1894,7 @@ gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
g_return_if_fail (iter != NULL); g_return_if_fail (iter != NULL);
g_return_if_fail (text != NULL); g_return_if_fail (text != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
start_offset = gtk_text_iter_get_offset (iter); start_offset = gtk_text_iter_get_offset (iter);
gtk_text_buffer_insert (buffer, iter, text, len); gtk_text_buffer_insert (buffer, iter, text, len);
@ -2024,7 +2029,7 @@ gtk_text_buffer_delete (GtkTextBuffer *buffer,
g_return_if_fail (end != NULL); g_return_if_fail (end != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
gtk_text_buffer_emit_delete (buffer, start, end); gtk_text_buffer_emit_delete (buffer, start, end);
} }
@ -2064,9 +2069,9 @@ gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
g_return_val_if_fail (gtk_text_iter_get_buffer (start_iter) == buffer, FALSE); g_return_val_if_fail (gtk_text_iter_get_buffer (start_iter) == buffer, FALSE);
g_return_val_if_fail (gtk_text_iter_get_buffer (end_iter) == buffer, FALSE); g_return_val_if_fail (gtk_text_iter_get_buffer (end_iter) == buffer, FALSE);
gtk_text_buffer_begin_user_action (buffer); gtk_text_buffer_begin_user_action (buffer);
gtk_text_iter_order (start_iter, end_iter); gtk_text_iter_order (start_iter, end_iter);
start_mark = gtk_text_buffer_create_mark (buffer, NULL, start_mark = gtk_text_buffer_create_mark (buffer, NULL,
@ -2165,7 +2170,7 @@ gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
gtk_text_buffer_delete_mark (buffer, end_mark); gtk_text_buffer_delete_mark (buffer, end_mark);
gtk_text_buffer_end_user_action (buffer); gtk_text_buffer_end_user_action (buffer);
return deleted_stuff; return deleted_stuff;
} }
@ -2202,7 +2207,7 @@ gtk_text_buffer_get_text (GtkTextBuffer *buffer,
g_return_val_if_fail (end != NULL, NULL); g_return_val_if_fail (end != NULL, NULL);
g_return_val_if_fail (gtk_text_iter_get_buffer (start) == buffer, NULL); g_return_val_if_fail (gtk_text_iter_get_buffer (start) == buffer, NULL);
g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL); g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL);
if (include_hidden_chars) if (include_hidden_chars)
return gtk_text_iter_get_text (start, end); return gtk_text_iter_get_text (start, end);
else else
@ -2240,7 +2245,7 @@ gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
g_return_val_if_fail (end != NULL, NULL); g_return_val_if_fail (end != NULL, NULL);
g_return_val_if_fail (gtk_text_iter_get_buffer (start) == buffer, NULL); g_return_val_if_fail (gtk_text_iter_get_buffer (start) == buffer, NULL);
g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL); g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL);
if (include_hidden_chars) if (include_hidden_chars)
return gtk_text_iter_get_slice (start, end); return gtk_text_iter_get_slice (start, end);
else else
@ -2255,7 +2260,7 @@ static void
gtk_text_buffer_real_insert_paintable (GtkTextBuffer *buffer, gtk_text_buffer_real_insert_paintable (GtkTextBuffer *buffer,
GtkTextIter *iter, GtkTextIter *iter,
GdkPaintable *paintable) GdkPaintable *paintable)
{ {
_gtk_text_btree_insert_paintable (iter, paintable); _gtk_text_btree_insert_paintable (iter, paintable);
g_signal_emit (buffer, signals[CHANGED], 0); g_signal_emit (buffer, signals[CHANGED], 0);
@ -2334,7 +2339,7 @@ gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
g_return_if_fail (iter != NULL); g_return_if_fail (iter != NULL);
g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor)); g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor));
g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
g_signal_emit (buffer, signals[INSERT_CHILD_ANCHOR], 0, g_signal_emit (buffer, signals[INSERT_CHILD_ANCHOR], 0,
iter, anchor); iter, anchor);
} }
@ -2360,11 +2365,11 @@ gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
GtkTextIter *iter) GtkTextIter *iter)
{ {
GtkTextChildAnchor *anchor; GtkTextChildAnchor *anchor;
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL); g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
g_return_val_if_fail (iter != NULL, NULL); g_return_val_if_fail (iter != NULL, NULL);
g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == buffer, NULL); g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == buffer, NULL);
anchor = gtk_text_child_anchor_new (); anchor = gtk_text_child_anchor_new ();
gtk_text_buffer_insert_child_anchor (buffer, iter, anchor); gtk_text_buffer_insert_child_anchor (buffer, iter, anchor);
@ -2385,7 +2390,7 @@ gtk_text_buffer_mark_set (GtkTextBuffer *buffer,
{ {
/* IMO this should NOT work like insert_text and delete_range, /* IMO this should NOT work like insert_text and delete_range,
* where the real action happens in the default handler. * where the real action happens in the default handler.
* *
* The reason is that the default handler would be _required_, * The reason is that the default handler would be _required_,
* i.e. the whole widget would start breaking and segfaulting if the * i.e. the whole widget would start breaking and segfaulting if the
* default handler didn't get run. So you can't really override the * default handler didn't get run. So you can't really override the
@ -2433,14 +2438,14 @@ gtk_text_buffer_set_mark (GtkTextBuffer *buffer,
GtkTextMark *mark; GtkTextMark *mark;
g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == buffer, NULL); g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == buffer, NULL);
mark = _gtk_text_btree_set_mark (get_btree (buffer), mark = _gtk_text_btree_set_mark (get_btree (buffer),
existing_mark, existing_mark,
mark_name, mark_name,
left_gravity, left_gravity,
iter, iter,
should_exist); should_exist);
_gtk_text_btree_get_iter_at_mark (get_btree (buffer), _gtk_text_btree_get_iter_at_mark (get_btree (buffer),
&location, &location,
mark); mark);
@ -2763,7 +2768,7 @@ gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
g_return_if_fail (iter != NULL); g_return_if_fail (iter != NULL);
g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor)); g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor));
g_return_if_fail (!gtk_text_child_anchor_get_deleted (anchor)); g_return_if_fail (!gtk_text_child_anchor_get_deleted (anchor));
_gtk_text_btree_get_iter_at_child_anchor (get_btree (buffer), _gtk_text_btree_get_iter_at_child_anchor (get_btree (buffer),
iter, iter,
anchor); anchor);
@ -2862,7 +2867,7 @@ gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
{ {
GtkTextTag *tag; GtkTextTag *tag;
va_list list; va_list list;
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL); g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
tag = gtk_text_tag_new (tag_name); tag = gtk_text_tag_new (tag_name);
@ -2879,7 +2884,7 @@ gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
g_object_set_valist (G_OBJECT (tag), first_property_name, list); g_object_set_valist (G_OBJECT (tag), first_property_name, list);
va_end (list); va_end (list);
} }
g_object_unref (tag); g_object_unref (tag);
return tag; return tag;
@ -2896,7 +2901,7 @@ gtk_text_buffer_real_apply_tag (GtkTextBuffer *buffer,
g_warning ("Can only apply tags that are in the tag table for the buffer"); g_warning ("Can only apply tags that are in the tag table for the buffer");
return; return;
} }
_gtk_text_btree_tag (start, end, tag, TRUE); _gtk_text_btree_tag (start, end, tag, TRUE);
} }
@ -2911,7 +2916,7 @@ gtk_text_buffer_real_remove_tag (GtkTextBuffer *buffer,
g_warning ("Can only remove tags that are in the tag table for the buffer"); g_warning ("Can only remove tags that are in the tag table for the buffer");
return; return;
} }
_gtk_text_btree_tag (start, end, tag, FALSE); _gtk_text_btree_tag (start, end, tag, FALSE);
} }
@ -2929,7 +2934,7 @@ gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
GtkTextMark *mark) GtkTextMark *mark)
{ {
GtkTextMark *insert; GtkTextMark *insert;
insert = gtk_text_buffer_get_insert (buffer); insert = gtk_text_buffer_get_insert (buffer);
if (mark == insert || mark == gtk_text_buffer_get_selection_bound (buffer)) if (mark == insert || mark == gtk_text_buffer_get_selection_bound (buffer))
@ -2937,7 +2942,7 @@ gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
gboolean has_selection; gboolean has_selection;
update_selection_clipboards (buffer); update_selection_clipboards (buffer);
has_selection = gtk_text_buffer_get_selection_bounds (buffer, has_selection = gtk_text_buffer_get_selection_bounds (buffer,
NULL, NULL,
NULL); NULL);
@ -2948,7 +2953,7 @@ gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
g_object_notify_by_pspec (G_OBJECT (buffer), text_buffer_props[PROP_HAS_SELECTION]); g_object_notify_by_pspec (G_OBJECT (buffer), text_buffer_props[PROP_HAS_SELECTION]);
} }
} }
if (mark == insert) if (mark == insert)
g_object_notify_by_pspec (G_OBJECT (buffer), text_buffer_props[PROP_CURSOR_POSITION]); g_object_notify_by_pspec (G_OBJECT (buffer), text_buffer_props[PROP_CURSOR_POSITION]);
} }
@ -3003,7 +3008,7 @@ gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
g_return_if_fail (tag->priv->table == buffer->priv->tag_table); g_return_if_fail (tag->priv->table == buffer->priv->tag_table);
gtk_text_buffer_emit_tag (buffer, tag, TRUE, start, end); gtk_text_buffer_emit_tag (buffer, tag, TRUE, start, end);
} }
@ -3034,7 +3039,7 @@ gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
g_return_if_fail (tag->priv->table == buffer->priv->tag_table); g_return_if_fail (tag->priv->table == buffer->priv->tag_table);
gtk_text_buffer_emit_tag (buffer, tag, FALSE, start, end); gtk_text_buffer_emit_tag (buffer, tag, FALSE, start, end);
} }
@ -3105,7 +3110,7 @@ gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
g_return_if_fail (end != NULL); g_return_if_fail (end != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
tag = gtk_text_tag_table_lookup (get_table (buffer), tag = gtk_text_tag_table_lookup (get_table (buffer),
name); name);
@ -3153,13 +3158,13 @@ gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
GSList *tmp_list; GSList *tmp_list;
GSList *prev, *next; GSList *prev, *next;
GtkTextTag *tag; GtkTextTag *tag;
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
g_return_if_fail (start != NULL); g_return_if_fail (start != NULL);
g_return_if_fail (end != NULL); g_return_if_fail (end != NULL);
g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer); g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
first = *start; first = *start;
second = *end; second = *end;
@ -3167,7 +3172,7 @@ gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
/* Get all tags turned on at the start */ /* Get all tags turned on at the start */
tags = gtk_text_iter_get_tags (&first); tags = gtk_text_iter_get_tags (&first);
/* Find any that are toggled on within the range */ /* Find any that are toggled on within the range */
tmp = first; tmp = first;
while (gtk_text_iter_forward_to_tag_toggle (&tmp, NULL)) while (gtk_text_iter_forward_to_tag_toggle (&tmp, NULL))
@ -3177,7 +3182,7 @@ gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
if (gtk_text_iter_compare (&tmp, &second) >= 0) if (gtk_text_iter_compare (&tmp, &second) >= 0)
break; /* past the end of the range */ break; /* past the end of the range */
toggled = gtk_text_iter_get_toggled_tags (&tmp, TRUE); toggled = gtk_text_iter_get_toggled_tags (&tmp, TRUE);
/* We could end up with a really big-ass list here. /* We could end up with a really big-ass list here.
@ -3193,7 +3198,7 @@ gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
g_slist_free (toggled); g_slist_free (toggled);
} }
/* Sort the list */ /* Sort the list */
tags = g_slist_sort (tags, pointer_cmp); tags = g_slist_sort (tags, pointer_cmp);
@ -3227,14 +3232,14 @@ gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
} }
g_slist_foreach (tags, (GFunc) g_object_ref, NULL); g_slist_foreach (tags, (GFunc) g_object_ref, NULL);
tmp_list = tags; tmp_list = tags;
while (tmp_list != NULL) while (tmp_list != NULL)
{ {
tag = GTK_TEXT_TAG (tmp_list->data); tag = GTK_TEXT_TAG (tmp_list->data);
gtk_text_buffer_remove_tag (buffer, tag, &first, &second); gtk_text_buffer_remove_tag (buffer, tag, &first, &second);
tmp_list = tmp_list->next; tmp_list = tmp_list->next;
} }
@ -3635,13 +3640,13 @@ pre_paste_prep (ClipboardRequest *request_data,
GtkTextIter *insert_point) GtkTextIter *insert_point)
{ {
GtkTextBuffer *buffer = request_data->buffer; GtkTextBuffer *buffer = request_data->buffer;
get_paste_point (buffer, insert_point, TRUE); get_paste_point (buffer, insert_point, TRUE);
if (request_data->replace_selection) if (request_data->replace_selection)
{ {
GtkTextIter start, end; GtkTextIter start, end;
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
{ {
if (request_data->interactive) if (request_data->interactive)
@ -3720,7 +3725,7 @@ paste_from_buffer (GdkClipboard *clipboard,
goto done; goto done;
} }
if (request_data->interactive) if (request_data->interactive)
gtk_text_buffer_begin_user_action (buffer); gtk_text_buffer_begin_user_action (buffer);
pre_paste_prep (request_data, &insert_point); pre_paste_prep (request_data, &insert_point);
@ -3737,7 +3742,7 @@ paste_from_buffer (GdkClipboard *clipboard,
request_data->interactive); request_data->interactive);
} }
if (request_data->interactive) if (request_data->interactive)
gtk_text_buffer_end_user_action (buffer); gtk_text_buffer_end_user_action (buffer);
done: done:
@ -3792,7 +3797,7 @@ update_selection_clipboards (GtkTextBuffer *buffer)
gdk_content_provider_content_changed (priv->selection_content); gdk_content_provider_content_changed (priv->selection_content);
else else
priv->selection_content = gtk_text_buffer_content_new (buffer); priv->selection_content = gtk_text_buffer_content_new (buffer);
for (l = priv->selection_clipboards; l; l = l->next) for (l = priv->selection_clipboards; l; l = l->next)
{ {
SelectionClipboard *selection_clipboard = l->data; SelectionClipboard *selection_clipboard = l->data;
@ -3826,7 +3831,7 @@ find_selection_clipboard (GtkTextBuffer *buffer,
SelectionClipboard *selection_clipboard = tmp_list->data; SelectionClipboard *selection_clipboard = tmp_list->data;
if (selection_clipboard->clipboard == clipboard) if (selection_clipboard->clipboard == clipboard)
return selection_clipboard; return selection_clipboard;
tmp_list = tmp_list->next; tmp_list = tmp_list->next;
} }
@ -3966,7 +3971,7 @@ gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
* flag toggles this behavior. * flag toggles this behavior.
*/ */
data->replace_selection = FALSE; data->replace_selection = FALSE;
get_paste_point (buffer, &paste_point, FALSE); get_paste_point (buffer, &paste_point, FALSE);
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end) && if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end) &&
(gtk_text_iter_in_range (&paste_point, &start, &end) || (gtk_text_iter_in_range (&paste_point, &start, &end) ||
@ -4067,12 +4072,12 @@ gtk_text_buffer_backspace (GtkTextBuffer *buffer,
if (gtk_text_iter_equal (&start, &end)) if (gtk_text_iter_equal (&start, &end))
return FALSE; return FALSE;
cluster_text = gtk_text_iter_get_text (&start, &end); cluster_text = gtk_text_iter_get_text (&start, &end);
if (interactive) if (interactive)
gtk_text_buffer_begin_user_action (buffer); gtk_text_buffer_begin_user_action (buffer);
if (gtk_text_buffer_delete_interactive (buffer, &start, &end, if (gtk_text_buffer_delete_interactive (buffer, &start, &end,
default_editable)) default_editable))
{ {
@ -4090,16 +4095,16 @@ gtk_text_buffer_backspace (GtkTextBuffer *buffer,
normalized_text, normalized_text,
g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text, g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
default_editable); default_editable);
g_free (normalized_text); g_free (normalized_text);
} }
retval = TRUE; retval = TRUE;
} }
if (interactive) if (interactive)
gtk_text_buffer_end_user_action (buffer); gtk_text_buffer_end_user_action (buffer);
g_free (cluster_text); g_free (cluster_text);
/* Revalidate the users iter */ /* Revalidate the users iter */
@ -4264,7 +4269,7 @@ gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer)
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
buffer->priv->user_action_count += 1; buffer->priv->user_action_count += 1;
if (buffer->priv->user_action_count == 1) if (buffer->priv->user_action_count == 1)
{ {
/* Outermost nested user action begin emits the signal */ /* Outermost nested user action begin emits the signal */
@ -4288,9 +4293,9 @@ gtk_text_buffer_end_user_action (GtkTextBuffer *buffer)
{ {
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
g_return_if_fail (buffer->priv->user_action_count > 0); g_return_if_fail (buffer->priv->user_action_count > 0);
buffer->priv->user_action_count -= 1; buffer->priv->user_action_count -= 1;
if (buffer->priv->user_action_count == 0) if (buffer->priv->user_action_count == 0)
{ {
/* Ended the outermost-nested user action end, so emit the signal */ /* Ended the outermost-nested user action end, so emit the signal */
@ -4351,7 +4356,7 @@ compute_log_attrs (const GtkTextIter *iter,
char *paragraph; char *paragraph;
int char_len, byte_len; int char_len, byte_len;
PangoLogAttr *attrs = NULL; PangoLogAttr *attrs = NULL;
start = *iter; start = *iter;
end = *iter; end = *iter;
@ -4374,7 +4379,7 @@ compute_log_attrs (const GtkTextIter *iter,
gtk_text_iter_get_language (&start), gtk_text_iter_get_language (&start),
attrs, attrs,
char_len + 1); char_len + 1);
g_free (paragraph); g_free (paragraph);
return attrs; return attrs;
@ -4392,7 +4397,7 @@ _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
int line; int line;
GtkTextLogAttrCache *cache; GtkTextLogAttrCache *cache;
int i; int i;
g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL); g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
g_return_val_if_fail (anywhere_in_line != NULL, NULL); g_return_val_if_fail (anywhere_in_line != NULL, NULL);
@ -4401,7 +4406,7 @@ _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
/* FIXME we also need to recompute log attrs if the language tag at /* FIXME we also need to recompute log attrs if the language tag at
* the start of a paragraph changes * the start of a paragraph changes
*/ */
if (priv->log_attr_cache == NULL) if (priv->log_attr_cache == NULL)
{ {
priv->log_attr_cache = g_slice_new0 (GtkTextLogAttrCache); priv->log_attr_cache = g_slice_new0 (GtkTextLogAttrCache);
@ -4413,7 +4418,7 @@ _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
{ {
clear_log_attr_cache (priv->log_attr_cache); clear_log_attr_cache (priv->log_attr_cache);
} }
cache = priv->log_attr_cache; cache = priv->log_attr_cache;
line = gtk_text_iter_get_line (anywhere_in_line); line = gtk_text_iter_get_line (anywhere_in_line);