PairedBraceMatcher with escaped brackets of the for \[ ... ]
In my language, constructs like \[Alpha] are possible. When I start typing \[ then IDEA automatically inserts the closing bracket ] which is OK as they are part of my PairedBraceMatcher. However, when I have finished typing \[Alpha<>] where <> is the position of the cursor and type the closing ] (again), I expect IDEA to simply jump over the already existing ]. This does not happen due to
if (iterator.getEnd() - iterator.getStart() != 1 || editor.getDocument().getCharsSequence().charAt(iterator.getStart()) != charTyped) {
return false;
}
in com.intellij.codeInsight.editorActions.TypedHandler#handleRParen. The charTyped is ], however charAt(iterator.getStart()) returns the backslash and therefore, the handleRParen returns without jumping over the existing ]. If it matters, my lexer returns \[Alpha] as one single token.
Question: Is there a way to handle this specific case differently so that the additional ] is not inserted? It would also be absolutely OK if I can turn off the automatic insertion of ] when I start typing \[.
Update:
One solution I found some seconds ago is to match \[ explicitly in my lexer. This returns a different token and the LEFT_BRACKET token is no longer visible. Then IDEA does of course not insert the closing ].
Please sign in to leave a comment.
> If it matters, my lexer returns \[Alpha] as one single token.
That platform code apparently works only when the closing bracket is a separate lexer token. As an alternative solution, you can implement your TypedHandlerDelegate#beforeCharTyped to handle such situation.