diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java index 88017450096..a50f7deedba 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java @@ -46,9 +46,7 @@ import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.KtNodeTypes; import org.jetbrains.kotlin.lexer.KtTokens; -import org.jetbrains.kotlin.psi.KtClassOrObject; -import org.jetbrains.kotlin.psi.KtFile; -import org.jetbrains.kotlin.psi.KtSimpleNameStringTemplateEntry; +import org.jetbrains.kotlin.psi.*; public class KotlinTypedHandler extends TypedHandlerDelegate { private final static TokenSet CONTROL_FLOW_EXPRESSIONS = TokenSet.create( @@ -230,8 +228,7 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { LtGtTypingUtils.handleKotlinAutoCloseLT(editor); return Result.STOP; } - - if (c == '{' && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) { + else if (c == '{' && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) { PsiDocumentManager.getInstance(project).commitAllDocuments(); int offset = editor.getCaretModel().getOffset(); @@ -242,9 +239,13 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { return Result.STOP; } } - - if (c == ':') { - if (autoIndentCase(editor, project, file)) { + else if (c == ':') { + if (autoIndentCase(editor, project, file, KtClassOrObject.class)) { + return Result.STOP; + } + } + else if (c == '.') { + if (autoIndentCase(editor, project, file, KtQualifiedExpression.class)) { return Result.STOP; } } @@ -293,14 +294,14 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { } } - private static boolean autoIndentCase(Editor editor, Project project, PsiFile file) { + private static boolean autoIndentCase(Editor editor, Project project, PsiFile file, Class kclass) { int offset = editor.getCaretModel().getOffset(); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); PsiElement currElement = file.findElementAt(offset - 1); if (currElement != null) { PsiElement parent = currElement.getParent(); - if (parent != null && parent instanceof KtClassOrObject) { - CodeStyleManager.getInstance(project).adjustLineIndent(file, offset - 1); + if (parent != null && kclass.isInstance(parent)) { + CodeStyleManager.getInstance(project).adjustLineIndent(file, offset - currElement.getText().length()); return true; } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt index 58005ca5d48..87e7181bfea 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt @@ -507,6 +507,44 @@ class TypedHandlerTest : LightCodeInsightTestCase() { """) } + fun testChainCallContinueWithDot() { + doCharTypeTest( + '.', + """ + |class Test{ fun test() = this } + |fun some() { + | Test() + | + |} + """, + """ + |class Test{ fun test() = this } + |fun some() { + | Test() + | . + |} + """) + } + + fun testChainCallContinueWithSafeCall() { + doCharTypeTest( + '.', + """ + |class Test{ fun test() = this } + |fun some() { + | Test() + | ? + |} + """, + """ + |class Test{ fun test() = this } + |fun some() { + | Test() + | ?. + |} + """) + } + fun testMoveThroughGT() { LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List>>") EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>')