diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index 54cd5eed396..11e90bb22dc 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -157,6 +157,13 @@ abstract class KotlinCommonBlock( return ChildAttributes(Indent.getNoneIndent(), null) } + if (type == KtNodeTypes.IF) { + val elseBlock = mySubBlocks?.getOrNull(newChildIndex) + if (elseBlock is ASTBlock && elseBlock.node.elementType == KtTokens.ELSE_KEYWORD) { + return ChildAttributes.DELEGATE_TO_NEXT_CHILD + } + } + return when (type) { in CODE_BLOCKS, KtNodeTypes.WHEN, KtNodeTypes.IF, KtNodeTypes.FOR, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE -> ChildAttributes(Indent.getNormalIndent(), null) diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt index d0e26ebcb0e..4adfc8f4301 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt @@ -557,6 +557,53 @@ class TypedHandlerTest : LightCodeInsightTestCase() { ) } + fun testIndentBeforeElseWithBlock() { + doCharTypeTest( + '\n', + """ + |fun test(b: Boolean) { + | if (b) { + | } + | else if (!b) { + | } + |} + """, + """ + |fun test(b: Boolean) { + | if (b) { + | } + | + | else if (!b) { + | } + |} + """ + ) + } + + fun testIndentBeforeElseWithoutBlock() { + doCharTypeTest( + '\n', + """ + |fun test(b: Boolean) { + | if (b) + | foo() + | else { + | } + |} + """, + """ + |fun test(b: Boolean) { + | if (b) + | foo() + | + | else { + | } + |} + """ + ) + } + + fun testMoveThroughGT() { LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List>>") EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>')