How to override the tab action in custom language (to insert 4 spaces instead of identing to a multiple of 4)?
Answered
I'm trying to create a custom action which always adds 4 spaces instead of adding a number of spaces so that the indentation would become a multiple of 4.
I've tried to create an action such as:
<actions>
<action id="RobotEditorTab" class="robotframework.idea.RobotTabAction">
<keyboard-shortcut keymap="$default" first-keystroke="tab" replace-all="true"/>
</action>
</actions>
but I get an exception that says: "first-keystroke" attribute has invalid value for action with id=RobotEditorTab [Plugin: robotframework.idea.robotframework-idea]
I also tried to add a custom typed handler:
<typedHandler implementation="robotframework.idea.RobotTabHandler"/>
But the `\t` never arrives there.
So, can someone give me any pointers on what would be the proper way to configure the `tab` behavior?
Please sign in to leave a comment.
Sorry this got lost. It should be possible by providing custom com.intellij.psi.codeStyle.FileIndentOptionsProvider for relevant files and returning corresponding com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions to have 4 spaces.
Hello Yann, thanks for answering, still, that doesn't really work.
i.e.: The problem is that in `com.intellij.openapi.editor.actions.TabAction` the `insertTabAtCaret` method always does:
`int spacesToAddCount = tabSize - columnNumber % Math.max(1,tabSize);`
So, it'll always add spaces to reach a multiple of the given indent size (and no attribute from `IndentOptions` provides a way to disable that and just add 4 spaces instead).
Given that, is there any other alternative to make it work?
Indeed. Please register custom com.intellij.openapi.editor.actionSystem.EditorActionHandler to customize Tab-Key handling, extending from EditorWriteActionHandler