String selectedText = this.textArea.getSelectedText();
// If text is selected just use that, otherwise select the nearest token.
if (selectedText == null)
{
RSyntaxDocument doc = (RSyntaxDocument) textArea.getDocument();
doc.readLock();
try
{
// Get the token at the caret position.
int line = textArea.getCaretLineNumber();
Token tokenList = textArea.getTokenListForLine(line);