Syntax Highlighting?

Can anyone point me in the right direction, with regards to syntax highlighting?
I have a text area, and I need to display each Xojo keyword in that text area, in the appropriate, default color (as in the IDE).

I have the list of Xojo keywords, but am unsure as to the correct approach to colorize any keywords which are found?
All pointers would be very much appreciated.

I have considered:
if statements
Select Case
Dictionary
Array

Thank you all in advance.

Google for “xojo syntax highlight” and you’ll get several free solutions

See for example https://forum.xojo.com/9808-syntaxhighlightingeditfield/p1#p70571

And https://forum.xojo.com/7994-syntax-highlighting/0

I was doing my own googling for the very same thing to try to enhance the CSS edit field in the newest version of Answers, but from what I understood all of those existing solutions (except for FTC) were outdated or didn’t work in the latest Xojo.

Did I misunderstand, are there updates, or could someone provide a little guidance?

I too, had already googled it, and all I can seem to find are outdated CustomEditFields??
I would prefer to use my current text area, and just run some kind of loop in order to colorize the keywords, but I do not know the best way to approach this - hence the request for directions :slight_smile:

Maybe this one is a starting point

https://dl.dropboxusercontent.com/u/992591/REALbasic/Forum/bitbatbut.rb.zip

Thanks Markus - I will take a look at Bit Bat Butt :slight_smile:

The project says it is using deprecated classes, so I looked at the actual code to see if I could understand what is happening.
Didn’t understand a word of it :frowning:

I guess I will have to use a mammoth select case in order to check for keywords.
Thanks anyway Markus.

look here Forum Post

You can customize colors in Constant XojoDef

Thanks Axel - I will take a look at that, and see if I can understand any of it :slight_smile:

I thought this sounded like a fun project to play with. Here’s a simplified solution. (Surprisingly fast too)
It could likely use some better error checking, and I can’t get the first word to color correctly if there’s not a leading space… but feel free to mess with it.

HighLighting.xojo_binary_project

@Axel: highlighting isn’t working in that project unless you change

Function KeyDown(Key As String) As Boolean mainwin.ContentsChanged = true return false End Function

to

Function KeyDown(Key As String) As Boolean mainwin.ContentsChanged = true me.highlight return false End Function

in the TextArea fld

@Jim: very nice :slight_smile:

Uses regEx like my bitbatbut but is faster. 30,000 characters with about 3000 hits in about 1 sec.

Thanks Jim - I will now take a look at yours, and see if I can understand any of that :slight_smile:

[quote=168533:@Markus Winter]@Axel: highlighting isn’t working in that project unless you change

Function KeyDown(Key As String) As Boolean mainwin.ContentsChanged = true return false End Function

to

Function KeyDown(Key As String) As Boolean mainwin.ContentsChanged = true me.highlight return false End Function

in the TextArea fld[/quote]

it works for me without these changes (OSX)

Strange, am on OSX myself.

Looking at the code where is the highlight method triggered? On first look I can’t find the place, that’s why I added the line.

it is keyListener.Reset in SyntaxHighlightEditField.TextChange

The place where it gets hairy is trying to color comments, but NOT comments within quotes ie. “//”“this is not a comment”"", that’s where I left off… you could probably keep an array of quoted ranges and compare against that when looking for comments. hmm…

Comments coloring works

Highlighting

the only problem is to remove the comment in quotes

Thanks, restart fixed the weird behaviour on my computer. Sorry for the noise.