RSyntaxTextArea 2.0.1 Released

All “.0″ releases have an obligatory follow-up maintenance release.  Grab RSyntaxTextArea 2.0.1 from SourceForge or Subversion today!  This release fixes the two following things:

  1. If SearchEngine selects text as part of a search/replace operation, and that text in a collapsed fold, the fold should be expanded to make the selection visible.
  2. The DTD for themes, theme.dtd, was not included in the 2.0.0 RSyntaxTextArea binary jar.  This made themes (one of the new features!) unusable since they could not be validated.

In addition, I made an API change.  I know it’s somewhat taboo to do that for minor releases, but it’s a straightforward change in your code to stay up to date.  This change is being made to support enhancements to the find/replace functionality in RSTA moving forward.

Previously, to do a find or replace operation in RSyntaxTextArea, you used one of the following methods from the SearchEngine class:

SearchEngine.find(JTextArea textArea, String text, boolean forward, boolean matchCase, boolean wholeWord, boolean regex);
SearchEngine.replace(JTextArea textArea, String toFind, String replaceWith, boolean forward, boolean matchCase, boolean wholeWord, boolean regex);
SearchEngine.replaceAll(JTextArea textArea, String toFind, String replaceWith, boolean matchCase, boolean wholeWord, boolean regex);

This is functional, but messy, and adding new options in the future would simply make the method signatures even longer (or introduce overloads).  To remedy this, I took a sip of the OO-KoolAid, and created a new SearchContext class.  This class keeps track of all information relevant to a find/replace operation.  The SearchEngine methods above now take a SearchContext instance as a parameter:

SearchEngine.find(JTextArea textArea, SearchContext context);
SearchEngine.replace(JTextArea textArea, SearchContext context);
SearchEngine.replaceAll(JTextArea textArea, SearchContext context);

This allows the searching API to stay clean, and adding support for a new search option is as easy as adding a new property to the SearchContext bean.  I hope to add support for at least two new search options in the future:  “search in selection” and “ignore comments.”

The actual SearchEngine class will likely be simplified as well.  Currently, it takes a different code path if you do a regex search than when you do a plain text search.  More code => more chances for bugs.  I’ll likely convert the plain text scenario into a regex one under the covers (convert your “find” text to a regex by escaping characters special for regular expressions).  This, along with making RSyntaxDocument a CharSequence, will greatly simplify the searching code, as well as provide a performance boost when searching large files.  All of this is implementation details of course, and won’t matter to someone just using the library.

Only RSyntaxTextArea has a 2.0.1 release.  AutoComplete, SpellChecker, etc. are still at 2.0.0 as they did not need any modifications.

Comments are closed.