Better indent in else-if editing (KT-14601)
#KT-14601 Fixed (cherry picked from commit 25d6d61)
This commit is contained in:
@@ -157,6 +157,13 @@ abstract class KotlinCommonBlock(
|
|||||||
return ChildAttributes(Indent.getNoneIndent(), null)
|
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) {
|
return when (type) {
|
||||||
in CODE_BLOCKS, KtNodeTypes.WHEN, KtNodeTypes.IF, KtNodeTypes.FOR, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE -> ChildAttributes(Indent.getNormalIndent(), null)
|
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() {
|
fun testMoveThroughGT() {
|
||||||
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List<Set<Int<caret>>>")
|
LightPlatformCodeInsightTestCase.configureFromFileText("a.kt", "val a: List<Set<Int<caret>>>")
|
||||||
EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>')
|
EditorTestUtil.performTypingAction(LightPlatformCodeInsightTestCase.getEditor(), '>')
|
||||||
|
|||||||
Reference in New Issue
Block a user