Better indent in else-if editing (KT-14601)

#KT-14601 Fixed

(cherry picked from commit 25d6d61)
This commit is contained in:
Nikolay Krasko
2017-04-06 20:42:16 +03:00
parent da9af682d9
commit d65b7a5b4b
2 changed files with 54 additions and 0 deletions
@@ -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)
@@ -557,6 +557,53 @@ class TypedHandlerTest : LightCodeInsightTestCase() {
)
}
fun testIndentBeforeElseWithBlock() {
doCharTypeTest(
'\n',
"""
|fun test(b: Boolean) {
| if (b) {
| }<caret>
| else if (!b) {
| }
|}
""",
"""
|fun test(b: Boolean) {
| if (b) {
| }
| <caret>
| else if (!b) {
| }
|}
"""
)
}
fun testIndentBeforeElseWithoutBlock() {
doCharTypeTest(
'\n',
"""
|fun test(b: Boolean) {
| if (b)
| foo()<caret>
| else {
| }
|}
""",
"""
|fun test(b: Boolean) {
| if (b)
| foo()
| <caret>
| else {
| }
|}
"""
)
}
fun testMoveThroughGT() {
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List<Set<Int<caret>>>")
EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>')