How do you programatically select text?

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

I’d like to click text in a meta tag and have the contents be selected/highlighted like you would if you manually dragged your mouse to select the whole string. How can this be done?

I’m not sure if this helps, but I’m pretty sure labels and other UI nodes in Godot are incapable of this. But I think if you have a TEXTEDIT node then it’s possible. The only downside is having your characters be able to edit the text. But then again, why would you want a player to highlight a text if it’s not to be edited?

TheJokingJack | 2021-07-11 15:55

:bust_in_silhouette: Reply From: db0

Assuming you’re talking about a RichTextLabel, the only way I see it is have the on_meta_clicked method connected to that signal, replace the bbcode between that [url] tag, with the same text, but wrapped with the extra bbcode tag you need. E.g. you could turn it underlined or change the font colour. Unfortunately the node does not offer a native way to change font background, but you can develop a custom effect to do that youself.