0 votes

Hi all, I am in the process of making a console.
I have a scene set up with a LineEdit to get input and two TextEdit readonly
one to output logs and one to output the valid command based on the input string.
Let's say the list of commands is this "specator, +specate, specmoveacc, player, +player, playermoveacc" and the input string is this "sp"
I want it to highlight only the macth for each command
In other words the desired result is this using grep to display the desired result
(I used grep a linux command to display the desired result)

This would seem a pretty trivial thing but I can't find any information on how to achieve it.
P.S. Sorry if this a duplicate question but I couldn't find my previous one on my questions tab so I think it didn't sumbit.

Godot version 3.5.1
in Engine by (12 points)

1 Answer

0 votes

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...

by (19,272 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.