Maybe someone will prove me wrong, but I'm not sure you can do exactly what you're after in a TextEdit
control. Basic syntax highlighting can be done in two different ways.
- On specified keywords, via
add_keyword_color()
- On a string of characters found between specified start and stop delimiters via
add_color_region()
The add_keyword_color()
is close to what you want, but it requires that the defined keywords be complete words (so, surrounded by whitespace).
So, in your example, you could easily define sp
as a keyword, but in this string...
special sp cusp hospital
only the lone sp
would be highlighted. The others would not since they aren't surrounded by whitespace characters.
That said, you probably could get the effect you want via a RichTextLabel
and bbcode
, but it might require significant changes to your current design...