mark up a word with underscore

Questions on using RSyntaxTextArea should go here.

Moderator: robert

mark up a word with underscore

Postby goran_schwarz » Wed Nov 14, 2012 7:28 pm

How do I select or mark a word by double click on a word with _ in the word

I just want the editor to recognize underscore to be part of the word
so by clicking on the word xxx_yyy the whole word "xxx_yyy" should be highligted so I can copy/delete it :)

Surly there must be a way:
textarea.setValidCharsInWords('_', '-') or similar

Posts: 6
Joined: Tue Aug 23, 2011 12:38 pm

Re: mark up a word with underscore

Postby robert » Thu Nov 15, 2012 4:31 am

Yes, word selection could probably be a little friendlier since underscores are pretty common while programming. Unfortunately, the only way to do this is to install a custom SelectWordAction into the text area's ActionMap. The built-in one creates a BeginWordAction and an EndWordAction as private fields, uses them to find the start and end of the word, and selects the range. You could either extend RSyntaxTextAreaEidtorKit.SelectWordAction, overriding createActions() to set "start" and "end" to Actions that allowed "_" as word chars, or write your own SelectWordAction from scratch (either one is probably the same amount of work). Something like this (untested):

java code:

Action a = new MySelectWordAction();
textArea.getActionMap().put(RTextAreaEditorKit.selectWordAction, a);
User avatar
Posts: 759
Joined: Sat May 10, 2008 5:16 pm

Return to Help

Who is online

Users browsing this forum: No registered users and 3 guests