Improved Syntax Highlighting and Theming Support

If you grab the latest from SVN, RSyntaxTextArea has improved theming support.  First, RSTA supports the following new token styles:

  • Markup language comments (i.e. “<!– … –>”)
  • DTDs
  • CDATA delimiters, separate from the CDATA content itself (e.g. “<![CDATA[" and "]]>”)
  • Entity references

Note that all of these are related to markup languages, such as XML, HTML, JSP and PHP.  Previously, the lexers for each of these languages identified and colorized all of these constructs, but re-used token styles for other token types when rendering them.  For example, entity references were previously rendered using the “variable” token style.  This wasn’t optimal, as it meant that theme designers had to be aware of this token-style re-use when creating custom Themes, if they wanted their Themes to be as pretty as possible.  Not so any longer!

Another new feature is that RSyntaxTextArea now supports the standard editor behavior of selected text using a different font color than unselected text.  Previously, selected text always still rendered using the proper syntax highlighting styles.  Now, this is configurable via the setUseSelectedTextColor(boolean)/getUseSelectedTextColor() API.  Theme XML can also specify how a theme wants this property set.  Below is a screenshot that compare the “dark” default theme, which has this property set to false, and the “eclipse” default theme, which has this property set to true:

Selected Text Rendering

Selected Text Rendering

Themes can also now use a special value “default” for selection foreground and background colors, which means “use the LookAndFeel’s (not system’s!) default for these values).  Check out the theme DTD for specifics.

These changes do unfortunately mean that themes created for older RSyntaxTextArea versions will no longer work with (the upcoming) 2.0.7+, as they will not pass validation against the DTD.  They can be easily updated however, so I don’t see this as much of an issue.

Finally, all of the sample themes have been updated to use the new features above.  Also, a new sample theme was added to the mix:  idea!  Thanks to Mikle Garin for this theme.  This is  obviously based off of IntelliJ IDEA‘s default theme.

IDEA Theme

IDEA Theme

Who knows, maybe a theme based off of its new Darcula will show up next.

Comments are closed.