Overriding tabulation insertion

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Overriding tabulation insertion

Postby as3boyan » Tue Sep 24, 2013 6:04 pm

When new line is created, seems like RSyntaxTextArea sets tabulation based on previous line, can I override this behaviour, to make my own calculations based on count of chars('(',')', '{','}')?

I want to change calculation of tab count to this:
RSyntaxTextArea.getTextBeforeCaret ->
Tab count: (countChar('(') + countChar('{') - countChar(')') - countChar('}') )

And I want to make custom Format function, which will do tab recalculation for each line of RSyntaxTextArea.

I just want to know where to start. (Please tell me which Action should I extend/use to do this)
as3boyan
 
Posts: 19
Joined: Mon Sep 16, 2013 8:21 pm

Re: Overriding tabulation insertion

Postby robert » Sat Sep 28, 2013 12:06 am

This logic is in the RSyntaxTextAreaEditorKit.InsertBreakAction. You can either override that (the keystroke it's assigned to in RSTADefaultInputMap), or possibly easier, extend an existing TokenMaker and override its getInsertBreakAction() method. RSTA checks whether the current TokenMaker (e.g. JavaTokenMaker, XmlTokenMaker, etc.) returns an action from this method, and if it does, it executes that instead of doing its own newline handling.

Take a look at AbstractJflexCTokenMaker to see how custom indentation is handled for C, C++, and Java.
User avatar
robert
 
Posts: 796
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron