app: [Wayland] fix invalid preedit range in text tool.
So it seems that pango_attr_iterator_range() could return G_MAXINT for a Pango attribute when it is at the end of the preedit string. Looking at Pango code, I see they initialize the attribute end property to PANGO_ATTR_INDEX_TO_TEXT_END (G_MAXUINT), later clamped to G_MAXINT by pango_attr_iterator_range(). So I guess for the specific case where we are at the text end, it is normal. Only weird thing is that this didn't happen at all on X11, only in Wayland. So let's do our own pre-check. Also double the check by adding a UTF-8 validation. This fixes preedit text not being displayed and the following warning: > Gtk-CRITICAL **: 12:31:25.118: gtk_text_buffer_emit_insert: assertion 'g_utf8_validate (text, len, NULL)' failed Even worse, this was potentially an out-of-range reading, though fortunately checked early enough.