Overriding tabulation insertion

Post a reply

:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review

Expand view Topic review: Overriding tabulation insertion

Re: Overriding tabulation insertion

Post by 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.

Overriding tabulation insertion

Post by 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)