Can CodeEdit render custom styles for arbitrary text ranges?

Godot Version

Godot 4.6.2

Question

TextEdit / CodeEdit: Arbitrary per-word styling?

Hi,

I’m building a custom console/log viewer using CodeEdit because I want to use features such as the gutter.

Each log entry can contain style tags that affect only parts of the text. For example:

[error]Failed[/error] to load save file.

where anything inside [error][/error] should be rendered in red.

I’m not talking about syntax highlighting. The styling comes from the log message itself, and a single line may contain multiple differently styled segments.

I don’t want to use RichTextLabel because I need gutter support and other editor-like features provided by TextEdit/CodeEdit.

My questions are:

  • Can TextEdit or CodeEdit apply styles to arbitrary text ranges?

  • Is there a way to customize rendering for specific words or character ranges?

  • Can the syntax-highlighting system be repurposed for this use case?

  • If not, would a custom control be the recommended solution?

Thanks!

#later

When this https://github.com/godotengine/godot/pull/119284 is merging

There’s probably a way to do it using regex, but I’ve not really used the syntax highlighter, however I can tell you how to customize specific keywords.

Simply extend the CodeEdit and create a new code highlighter:



func _ready() → void:
    var highlighter = CodeHighlighter.new()
    highlighter.add_keyword_color(“error”, Color.RED)
    highlighter.add_keyword_color(“warning”, Color.ORANGE)
    syntax_highlighter = highlighter

Yeah, simple code highlighting will not cut it for me

What I want was richTextEdit

With more research on this topic, later, I found this full request

With exact thing I want from the implementation

So I think I have to wait

The reason why I am using textEdit instead of richTextLabel it’s because I am using custom gutter to show tags like time or level and with this, I can even collapse them

And one big decision is it handle auto wrap out, flip box, meaning if a line is too long, due to the gutters, it will look as indentation

And right now, I am trying to implement line folding as well