A Syntax Highlighting TextArea with LineNumbers

textAreaRDS is a custom subclass of the TextArea control found in Xojo™.
It has been enhanced to include Syntax Highlighting, Linenumbers and Character Ruler and Bookmarks.

Current version is for macOS only due to OS specific declares. A Windows version may be developed in the future.

A demo can be downloaded at http://www.rdS.com/textAreaRDS.zip
This demo contains an encrypted version of the control, and is FREE to use in any project as long as you include an Acknowlegment in your “About” dialog.
The full source code is also available for $50US, just drop me an email

This has a footprint less that 1/10th that of CEF (abeit without ALL the same features) :slight_smile:

New functions

BOOKMARKS

  • bookMarks() : allows application to set or get all available bookmarked linenumbers

  • bookMarkAdd(linenumber) : adds a bookmark to specified line

  • bookMarkClear() : removes all existing bookmarks

  • bookMarkNEXT : jump to the next bookmark (wrapping if required)

  • bookMarkPREV : jump to the previous bookmark (wrapping if required)

  • bookMarkREMOVE(linenumber) : remove the bookmark on specified line

  • bookMarkToggle(linenumber) : toggle the bookmark on specified line

  • GotoLine(linenumber) : jump to specified line if it exists

SYNTAX HIGHLIGHTING

  • Comments : set/get the color used for Comments designated by //
  • GutterBackgroundColor : set/get color for Linenumber Gutter area
  • Keywords : set/get color used to display Keywords in the text
  • LineNumberColor : set/get the color used for displaying linenumber in Gutter area
  • Numbers : set/get color used to display Number in the text
  • QuotedText : set/get color used to display quoted strings in the text
  • TextColor : set/get color used to display all other text
  • TextFont : font used to display text [must be mono-spaced]
  • TextSize : size of font used to display text

MISC

  • Contents : set/get the contents of the editor
  • KeywordList : set/get an array of keywords to highlight
  • ShowGutter : show/hide the linenumber gutter
  • ShowRuler : show/hide the Character Ruler
  • ShowStatus : show/hide the position status line

really surprised… I thought there would be “some” interest… at least I can use if for my own projects :slight_smile:

Looks very nice but being macOS only is a real issue.

understood… well if anyone can come up with the Windows equivalent of this… I can make it work

#If TargetCocoa
  Declare Sub setAutomaticQuoteSubstitutionEnabled Lib "Cocoa" selector "setAutomaticQuoteSubstitutionEnabled:" (obj As ptr, value As Boolean)
  Declare Function documentView Lib "Cocoa" selector "documentView" (obj As ptr) As ptr
  setAutomaticQuoteSubstitutionEnabled(documentView(ptr(Me.Handle)),False)
  //
  // make TextArea Transparent
  Declare Sub setDrawBack  Lib "Cocoa" selector "setDrawsBackground:"(id As Integer, b As Boolean)
  Declare Function docView Lib "Cocoa" selector "documentView"(id As Integer) As Integer
  setDrawBack(Me.Handle, False)
  setDrawBack(docView(Me.Handle), False)
#Else
  // this is a syntax error on purpose.
  This control can only be compiled For macOS/Cocoa, sorry.
#EndIf

Not tested it (yet). But what does it Syntax highlight? All known code languages?

BTW the download link doesn’t work.

It highlights what ever word list you provide

me.KeywordList="For,Next,Print"

use comma, pipe or linefeed

link should work now

Very useful control. Thumbs up!

Few questions… Are you able to make this work in Dark Mode? I tried it but it seems not to work with the rulers/line number indicators.

Also, it would be cool if it took a RegEx pattern instead of a fixed set of strings; useful when you have to take an arbitrary # of characters within a context and highlight it all (like setting a markdown sentence to bold).

Cheers

  1. All the colors are definable… but the linenumber gutter and ruler are canvas controls and therefore not subject to “dark” mode… I guess it could be enhanced to have two sets of color attributes one for light and one for dark

  2. All the syntax highlighting is currently done with RegEx, so your suggestion would be quite doable… But currently the Syntax Highlighting is foreground color only… I decided against including Bold/Italic/Underline, but it could be enhanced for that as well

Yeah I was not expecting the control to change the matched text to bold, italic etc. I was mostly planning to use it to syntax highlight in a different color the raw markdown code.

Highlighting the text and URL within a link like this comes to mind.