in src/main/kotlin/org/arend/codeInsight/ArendTypedHandler.kt [85:124]
override fun charTyped(c: Char, project: Project, editor: Editor, file: PsiFile): Result {
if (file !is ArendFile) {
return super.charTyped(c, project, editor, file)
}
if (c == '{' || c == '(') {
return Result.STOP // To prevent auto-formatting
}
val offset = editor.caretModel.offset
val document = editor.document
val text = document.charsSequence
val atRBrace = offset < text.length && text[offset] == '}'
if (atRBrace && c == '}' && offset > 2 && text[offset - 3] == '{' && text[offset - 2] == '?') {
PsiDocumentManager.getInstance(project).commitDocument(document)
document.deleteString(offset, offset + 1)
return Result.STOP
}
if (c != '-') {
return Result.CONTINUE
}
val style = service<ArendSettings>().matchingCommentStyle
if (style == ArendSettings.MatchingCommentStyle.DO_NOTHING || style == ArendSettings.MatchingCommentStyle.INSERT_MINUS && !CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) {
return Result.CONTINUE
}
PsiDocumentManager.getInstance(project).commitDocument(document)
if (atRBrace && offset > 1 && text[offset - 2] == '{') {
if (style == ArendSettings.MatchingCommentStyle.INSERT_MINUS) {
document.insertString(offset, CharArrayCharSequence('-'))
} else {
document.deleteString(offset, offset + 1)
}
}
return Result.CONTINUE
}