Color code text in a TextBox

I basically want to make a code editor plugin, but I need it to look clean.

I want text to be color coded, like this:

Does anyone know how to do this efficiently and easily?

Best i could think of is make a table of word colors.

Example:

local wordColors = {{"local",Color3.FromRGB(255,255,0)}}

and then loop through it.

Here’s a refrence: String Patterns

local wordColors = {{"local",Color3.FromRGB(255,255,0)}}

for i,v in pairs(WordColors) do
local FoundMatch = string.match("local Test = 5", v[1])
if FoundMatch then
local color = v[2]
--do rich text stuff here.
end
end

ps: sorry for my deleted posts. My laptop is kinda acting up.

First, you’ll need a list of reserved keywords to highlight (and , break , do , else , elseif , end , false , for , function , if , in , local , nil , not , or , repeat , return , then , true , until , while).

You’ll need RichText enabled, and you’ll need to frequently check the text that the user is inputting and use string manipulation to add color tags around keywords.

e.g.

local could become <font color="#0000FF">local</font>

You’ll need to preserve a copy of the user’s input somehow, because you obviously don’t want to overwrite it.

What you’re describing is a task easier said than done which cannot be completed quickly and easily, so I can’t make a fully functional version of what you’re asking for and give it to you, but I hope this helps to guide you in the right direction.

2 Likes

So I guess change the text everytime GetPropertyChangedSignal() is fired?

I really just want to know if theres any other way to do this, I would be wasting hours of time.

You could do that or update every frame with RunService.Heartbeat, but my honest opinion is that you probably shouldn’t go through all the effort of making this if it’s just meant to be a nice extra feature for your plugin. What you’re describing is effectively making your own text editor with its own syntax highlighting. This isn’t something you can do with just a couple of lines of code, this is a major project on its own.

I think @boatbomber has made a command bar plugin with a similar concept.

I believe this is what you’re referring to:

It’s certainly doable, but definitely not without sinking hours into it; I believe the OP was hoping there’d be an easy way to do this. Coloring text is easy, but making a text editor isn’t.

I open sourced something to make this easy for you!

7 Likes

Hey, just wondering, what is a builtin, a operator, and an iden?