GtkTextTag.underline does not work over empty text
In gtksourceview#217 (closed) we seem to have a problem where underlines are not being applied because there is no text associated with the underline location.
This is used to find erroneous trailing spacing and display it to the user as a warning.
This test shows the issue as well:
gcc test.c -o test $(pkg-config --cflags --libs gtk4)
#include <gtk/gtk.h>
static GMainLoop *loop;
int
main (int argc,
char *argv[])
{
GtkWidget *window;
GtkWidget *text;
GtkTextBuffer *buffer;
GtkTextIter iter, begin, end;
GtkTextTag *tag;
GdkRGBA rgba;
gtk_init ();
gdk_rgba_parse (&rgba, "#999999");
window = g_object_new (GTK_TYPE_WINDOW, NULL);
text = gtk_text_view_new ();
gtk_window_set_child (GTK_WINDOW (window), text);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
gtk_text_buffer_get_start_iter (buffer, &iter);
gtk_text_buffer_insert (buffer, &iter, " x \n ", -1);
tag = gtk_text_buffer_create_tag (buffer, NULL,
//"background-rgba", &rgba,
"underline", PANGO_UNDERLINE_DOUBLE,
"underline-rgba", &rgba,
NULL);
//gtk_text_buffer_get_iter_at_offset (buffer, &begin, 2);
//gtk_text_buffer_get_iter_at_offset (buffer, &end, 6);
gtk_text_buffer_get_bounds (buffer, &begin, &end);
gtk_text_buffer_apply_tag (buffer, tag, &begin, &end);
gtk_window_present (GTK_WINDOW (window));
loop = g_main_loop_new (NULL, FALSE);
g_signal_connect_swapped (window, "close-request", G_CALLBACK (g_main_loop_quit), loop);
g_main_loop_run (loop);
return 0;
}