Skip to content

Commit

Permalink
[ type handler ] Handle typing event in Java and Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Apr 20, 2018
1 parent 0946490 commit 527aa57
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions common/src/org/ice1000/devkt/lang/languages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.com.intellij.openapi.fileTypes.PlainTextLanguage
import org.jetbrains.kotlin.com.intellij.openapi.project.Project
import org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.lexer.KotlinLexer
import javax.swing.Icon
Expand Down Expand Up @@ -82,6 +83,13 @@ sealed class BuiltinDevKtLanguage<TextAttributes>(
override fun satisfies(fileName: String) = false
override val lineCommentStart = "//"
override val blockComment: Pair<String, String>? = "/*" to "*/"
override fun handleTyping(offset: Int, text: String?, element: PsiElement?, document: IDevKtDocumentHandler<TextAttributes>) {
element.takeIf { text == "\n" }?.run {
val whitespace = containingFile.findElementAt(document.startOffsetOf(document.lineOf(offset)))
as? PsiWhiteSpace ?: return@run null
super.handleTyping(offset, whitespace.text, element, document)
} ?: super.handleTyping(offset, text, element, document)
}
}

/**
Expand Down

0 comments on commit 527aa57

Please sign in to comment.