Fix quote handler for character literals
#KT-12385 Fixed
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.editor
|
|||||||
import com.intellij.codeInsight.editorActions.QuoteHandler
|
import com.intellij.codeInsight.editorActions.QuoteHandler
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator
|
import com.intellij.openapi.editor.highlighter.HighlighterIterator
|
||||||
import com.intellij.psi.tree.IElementType
|
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
|
||||||
class KotlinQuoteHandler : QuoteHandler {
|
class KotlinQuoteHandler : QuoteHandler {
|
||||||
@@ -40,7 +39,7 @@ class KotlinQuoteHandler : QuoteHandler {
|
|||||||
override fun isOpeningQuote(iterator: HighlighterIterator, offset: Int): Boolean {
|
override fun isOpeningQuote(iterator: HighlighterIterator, offset: Int): Boolean {
|
||||||
val tokenType = iterator.tokenType
|
val tokenType = iterator.tokenType
|
||||||
|
|
||||||
if (tokenType == KtTokens.OPEN_QUOTE) {
|
if (tokenType == KtTokens.OPEN_QUOTE || tokenType == KtTokens.CHARACTER_LITERAL) {
|
||||||
val start = iterator.start
|
val start = iterator.start
|
||||||
return offset == start
|
return offset == start
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -552,6 +552,10 @@ class TypedHandlerTest : LightCodeInsightTestCase() {
|
|||||||
checkResultByText("val a: List<Set<Int>><caret>")
|
checkResultByText("val a: List<Set<Int>><caret>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testCharClosingQuote() {
|
||||||
|
doCharTypeTest('\'', "val c = <caret>", "val c = ''")
|
||||||
|
}
|
||||||
|
|
||||||
private fun doCharTypeTest(ch: Char, beforeText: String, afterText: String) {
|
private fun doCharTypeTest(ch: Char, beforeText: String, afterText: String) {
|
||||||
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", beforeText.trimMargin())
|
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", beforeText.trimMargin())
|
||||||
EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), ch)
|
EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), ch)
|
||||||
|
|||||||
Reference in New Issue
Block a user