Merge pull request #155 from ZoiteChat/fix-input-color-rendering

Hide formatting control bytes again
This commit is contained in:
deepend-tildeclub
2026-03-24 19:51:59 -06:00
committed by GitHub

View File

@@ -348,24 +348,13 @@ gtk_entry_find_position (GtkEntry *entry, gint x)
static void static void
insert_hiddenchar (SexySpellEntry *entry, guint start, guint end) insert_hiddenchar (SexySpellEntry *entry, guint start, guint end)
{ {
/* FIXME: Pango does not properly reflect the new widths after a char
* is 'hidden' */
#if 0
PangoAttribute *hattr; PangoAttribute *hattr;
PangoRectangle *rect = g_new (PangoRectangle, 1); PangoRectangle rect = { 0 };
rect->x = 0; hattr = pango_attr_shape_new (&rect, &rect);
rect->y = 0;
rect->width = 0;
rect->height = 0;
hattr = pango_attr_shape_new (rect, rect);
hattr->start_index = start; hattr->start_index = start;
hattr->end_index = end; hattr->end_index = end;
pango_attr_list_insert (entry->priv->attr_list, hattr); pango_attr_list_insert (entry->priv->attr_list, hattr);
g_free (rect);
#endif
} }
static void static void
@@ -1089,6 +1078,7 @@ check_attributes (SexySpellEntry *entry, const char *text, int len)
break; break;
case ATTR_COLOR: case ATTR_COLOR:
insert_hiddenchar (entry, i, i + 1);
parsing_color = 1; parsing_color = 1;
offset = 1; offset = 1;
break; break;
@@ -1102,6 +1092,7 @@ check_color:
{ {
if (text[i] == ',' && parsing_color <= 3) if (text[i] == ',' && parsing_color <= 3)
{ {
insert_hiddenchar (entry, i, i + 1);
parsing_color = 3; parsing_color = 3;
offset++; offset++;
continue; continue;
@@ -1118,21 +1109,25 @@ check_color:
{ {
case 1: case 1:
fg_color[0] = text[i]; fg_color[0] = text[i];
insert_hiddenchar (entry, i, i + 1);
parsing_color++; parsing_color++;
offset++; offset++;
continue; continue;
case 2: case 2:
fg_color[1] = text[i]; fg_color[1] = text[i];
insert_hiddenchar (entry, i, i + 1);
parsing_color++; parsing_color++;
offset++; offset++;
continue; continue;
case 3: case 3:
bg_color[0] = text[i]; bg_color[0] = text[i];
insert_hiddenchar (entry, i, i + 1);
parsing_color++; parsing_color++;
offset++; offset++;
continue; continue;
case 4: case 4:
bg_color[1] = text[i]; bg_color[1] = text[i];
insert_hiddenchar (entry, i, i + 1);
parsing_color++; parsing_color++;
offset++; offset++;
continue; continue;
@@ -1162,13 +1157,31 @@ check_color:
} }
} }
} }
if (parsing_color)
{
if (bg_color[0] != 0)
{
insert_hiddenchar (entry, len - offset, len);
insert_color (entry, len, atoi (fg_color), atoi (bg_color));
}
else if (fg_color[0] != 0)
{
insert_hiddenchar (entry, len - offset, len);
insert_color (entry, len, atoi (fg_color), -1);
}
else
{
insert_hiddenchar (entry, len - offset, len - offset + 1);
insert_color (entry, len, -1, -1);
}
}
} }
static gboolean static gboolean
attr_list_has_attrs (PangoAttrList *attrs) attr_list_has_attrs (PangoAttrList *attrs)
{ {
PangoAttrIterator *it; PangoAttrIterator *it;
GSList *list;
gboolean has = FALSE; gboolean has = FALSE;
if (!attrs) if (!attrs)
@@ -1178,9 +1191,15 @@ attr_list_has_attrs (PangoAttrList *attrs)
if (!it) if (!it)
return FALSE; return FALSE;
list = pango_attr_iterator_get_attrs (it); do
{
GSList *list = pango_attr_iterator_get_attrs (it);
has = (list != NULL); has = (list != NULL);
g_slist_free_full (list, (GDestroyNotify) pango_attribute_destroy); g_slist_free_full (list, (GDestroyNotify) pango_attribute_destroy);
if (has)
break;
}
while (pango_attr_iterator_next (it));
pango_attr_iterator_destroy (it); pango_attr_iterator_destroy (it);
return has; return has;