textbuffer: Don't try to inset NULL text from clipboard

That used to generate a critical error message.

Also free() the data.
This commit is contained in:
Timm Bäder 2020-09-19 18:41:10 +02:00
parent 9eaa8bd1e7
commit 12cc178756

View File

@ -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;
char *data;
written = g_output_stream_splice_finish (stream, result, &error); written = g_output_stream_splice_finish (stream, result, &error);
if (written < 0) if (written < 0)
@ -318,16 +319,20 @@ gtk_text_buffer_deserialize_text_plain_finish (GObject *source,
return; return;
} }
data = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (
g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (stream))));
if (data)
{
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, gtk_text_buffer_insert (buffer, &end, data, -1);
&end,
g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (
g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (stream)))),
-1);
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);
g_free (data);
}
gdk_content_deserializer_return_success (deserializer); gdk_content_deserializer_return_success (deserializer);
} }