griddycode icon indicating copy to clipboard operation
griddycode copied to clipboard

Allow regex in highlight and/or add ability for custom highlighting function

Open Symmettry opened this issue 1 year ago • 8 comments

tryna make a typescript highlight but unfortunately I can't highlight types since it's ": any" but I don't have regex to capture that.

Symmettry avatar Mar 22 '24 05:03 Symmettry

I don't see how that would be possible without modifying the GoDot engine's source code, as highlight_region is the only method remotely close to RegEx. I would love to be wrong & be corrected that there is a way, so for now I'll leave this issue opened

face-hh avatar Mar 22 '24 05:03 face-hh

https://docs.godotengine.org/en/stable/classes/class_regex.html

for version 4.2 (the one i'm pretty sure you use):

var regex = RegEx.new() regex.compile("\w-(\d+)")

which then you can do

var result = regex.search("abc n-0123") if result: print(result.get_string())

Symmettry avatar Mar 22 '24 05:03 Symmettry

And also the custom highlighting function would be useful outside of this anyway

Symmettry avatar Mar 22 '24 05:03 Symmettry

Yes, the RegEx resource exists in Godot, however the CodeEdit node can only highlight using keywords and regions - no "from index 3 to index 7, color red"

Which, again, goes to:

I don't see how that would be possible without modifying the GoDot engine's source code

face-hh avatar Mar 22 '24 15:03 face-hh

Ah i see, that’s unfortunate.

Symmettry avatar Mar 22 '24 19:03 Symmettry

Are you able to remove old highlights? If so you could add custom highlighting which highlights a region matched by regex in the lua script then remove the old matches. Although i’m unsure how efficient it is…probably should try to get the code edit thing to allow regex / color by index->index

Symmettry avatar Mar 24 '24 07:03 Symmettry

A region must have a symbol as the first match, not just any character.

face-hh avatar Mar 24 '24 07:03 face-hh