a Syntax Highlighting TextArea Control

I am about to start a new project, and had a need for a “simple” syntax highlighting textarea control. It didn’t have to be fancy… and it didn’t have to handle thousands of lines of text… so I came up with this… only took about an hour to make it work (which surprised me)…

Anyways… if anyone needs something simple, below is a link to the source code. It uses RegEx to do all the work (THANKS KEM!) , but it is still a bit of “brute force”

Feel free to use it in any project, and if you feel like making a donation… I won’t complain.
Donate

A Simple Syntax Highlighting TextArea Control

  • supports colors for Keywords, Numbers, Operators, Line Comments, Block Comments
  • keyword list can be changed by adding or deleting words in one specific method…

Try this one
Define a table named “FROM” with a column named “FROM” - which is legal in a lot of engines (some will reject it which is actually incorrect but…)
Then “select from from from” :stuck_out_tongue:

Context matters as to whether FROM is or is not a key word vs a table name vs a column name
Yes its a really extreme example but I’ve seen such things

Just like in Xojo where you can do

   dim string as string = "123"

:stuck_out_tongue:

hence the descriptive word “SIMPLE”

heck even Xojo doesn’t handle all manners of context… including

dim string as string = "123"

In a project I use Lexing control from @Alfred Van Hoek .
It’s not simple to implement but once you have it working it works really great. i use it for SQL queries.

Lexing control was included in a Omega bundle, think it was 2014.

Short test on Windows 10:
Tab - key: selects the whole line, but doesn’t tab
Return - key: doesn’t go to the next line (does nothing)
Enter - key: same as Return - key.

My knowlege of regex is close to zero, therefor i am not capable to show where the problem is.

on Ubuntu:

Tab: ok
Return: nothing

on paste only the first line from clipboard is inserted

got Return working by adding Multiline in Inspector Behavior in myTextArea and set it to True in the Inspector Pane.

[quote=318137:@Andre Kuiper]Short test on Windows 10:
Tab - key: selects the whole line, but doesn’t tab
Return - key: doesn’t go to the next line (does nothing)
Enter - key: same as Return - key.

My knowlege of regex is close to zero, therefor i am not capable to show where the problem is.[/quote]

This makes no sense, as it is a TEXTAREA control, and those keys are not being interfered with.
And I THOUGHT I’d set Multiline to be true…

When I change highlight colors in the Inspector, it crashes on start

to prevent that, add (as first line) in the Method ‘highlight’

if me.Text = "" then Return

Thanks Axel…
I have made the following changes (so far)

  • Added the line you suggested
  • Set MultiLine to TRUE in the Inspector (thought I had already, but seems not)
  • Exposed the AcceptsTab property

Open to any other anomolies, or improvements.
Again, this is not meant to replace more powerful TextEditors… it will be for a SQLite Manager

[quote=318120:@Dave S]
heck even Xojo doesn’t handle all manners of context… including

dim string as string = "123" [/quote]
Yes - I know
Hence the reason we want to make the IDE use the compiler to drive autocomplete etc as it definitely gets typing in context right.

my personal opinion, Xojo (nor any other language for that matter) should NOT allow variables, symbols or constants to be named the same as any keyword or datatype. Especially where the language is not case sensitive… It leads to future confusion, and I humbly submit it is a bad practice/habit to get into.
So the fact that the Highlighter does NOT recognize context, could be considered a GOOD thing, as it helps identify places where you have slipped into this paradigm

[quote=318196:@Dave S]my personal opinion, Xojo (nor any other language for that matter) should allow variables, symbols or constants to be named the same as any keyword or datatype. Especially where the language is not case sensitive… It leads to future confusion, and I humbly submit it is a bad practice/habit to get into.
So the fact that the Highlighter does NOT recognize context, could be considered a GOOD thing, as it helps identify places where you have slipped into this paradigm[/quote]
Did you miss a ‘not’?

not that I am aware… where do you think I missed it?

To easily add new keywords, you can use a constant (mykeywords as a string)

[quote]
Alter
Table
Add
Where
From
…[/quote]

in makeKeywords

words = Split(mykeywords, EndOfLine)

… should NOT allow …

Ahhhh… .right :slight_smile:

[quote=318167:@Dave S]Thanks Axel…
I have made the following changes (so far)

  • Added the line you suggested
  • Set MultiLine to TRUE in the Inspector (thought I had already, but seems not)
  • Exposed the AcceptsTab property

Open to any other anomolies, or improvements.
Again, this is not meant to replace more powerful TextEditors… it will be for a SQLite Manager[/quote]

Is there a new download with the items fixed?

Actually there is…

www.rdS.com/mytextArea.xojo_xml_project.zip

Note… this zip is not an entire “project”… it is just the class and some odd bits… it is up to you to integrate into your own project

There were additional changes made since my last post, when one of the testers for my Tadpole project noticed big issues when running under Windows, and the need to disable “smart quotes”… both of these have been fixed

Change Log
----------
22Jun2017 [RDS]
- added timer methods to update display only during keyboard idle time
- changed to only apply highlight to VISIBLE text... mainly to reduce flicker in Window
- added Declares for macOS to disable "SmartQuotes"

27Feb2017 [RDS]
- Added check for null text in HIGHLIGHT method
- Set MultiLine to TRUE in Property Inspector
- Exposed AcceptsTabs in Property Inspector