Color single characters in TextEdit

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pederbacher

I want to color single characters in a TextEdit. Currently, it supports coloring a keyword with “add_keyword_color()”, but a keyword requires a symbol (or space) before and after to be identified, e.g. so one cannot just color all “a” easily.

I simply cannot figure out how to color a single character (or a sequence no surrounded by symbols), can anyone give some idea on how to do that?

Can I write a new function for the TextEdit which does that, maybe coloring (or setting some other font property) with regular expressions etc.

Actually, I did make a hack, by modding a font to include a zero width space and then inserting that all the time the text is changed.

Thanks in advance!

:bust_in_silhouette: Reply From: Zylann

I don’t think TextEdit supports that, or was even meant to color single characters aribtrarily.
That’s more like something you would find in RichTextLabel, although it cannot be edited by the user.
You’d have to build a custom text editor from that if your needs are simple.

Maybe this PR will help you color TextEdit in the future: