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 817b36aca57..069a6c823d7 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -277,7 +277,7 @@ abstract class KotlinCommonBlock( if (parentType === VALUE_PARAMETER_LIST || parentType === VALUE_ARGUMENT_LIST) { val prev = getPrevWithoutWhitespace(child) - if (childType === RPAR && (prev == null || prev.elementType !== TokenType.ERROR_ELEMENT)) { + if (childType === RPAR && (prev == null || prev.elementType !== COMMA || !hasDoubleLineBreakBefore(child))) { return Indent.getNoneIndent() } diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt index f024009e61e..cbe0b6ae4c0 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/TypedHandlerTest.kt @@ -8,8 +8,10 @@ package org.jetbrains.kotlin.idea.editor import com.intellij.application.options.CodeStyle +import com.intellij.psi.codeStyle.CodeStyleSettings import com.intellij.testFramework.EditorTestUtil import org.jetbrains.kotlin.idea.KotlinFileType +import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle import org.jetbrains.kotlin.idea.formatter.ktCodeStyleSettings import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase @@ -857,6 +859,98 @@ class TypedHandlerTest : KotlinLightCodeInsightTestCase() { ) } + private val settingsWithInvertedAlignWhenMultiline = { + val settings = CodeStyleSettings().getCommonSettings(KotlinLanguage.INSTANCE) + settings.ALIGN_MULTILINE_PARAMETERS = !settings.ALIGN_MULTILINE_PARAMETERS + settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = !settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS + enableSmartEnterWithTabs()() + } + + fun testSmartEnterWithTabsOnConstructorParametersWithInvertedAlignWhenMultiline() { + doTypeTest( + '\n', + """ + |class A( + | a: Int, + |) + """, + """ + |class A( + | a: Int, + | + |) + """, + settingsWithInvertedAlignWhenMultiline + ) + } + + fun testSmartEnterWithTabsInMethodParametersWithInvertedAlignWhenMultiline() { + doTypeTest( + '\n', + """ + |fun method( + | arg1: String, + |) {} + """, + """ + |fun method( + | arg1: String, + | + |) {} + """, + settingsWithInvertedAlignWhenMultiline + ) + } + + fun testEnterWithoutLineBreakBeforeClosingBracketInMethodParametersWithInvertedAlignWhenMultiline() { + doTypeTest( + '\n', + """ + |fun method( + | arg1: String,) {} + """, + """ + |fun method( + | arg1: String, + |) {} + """, + settingsWithInvertedAlignWhenMultiline + ) + } + + fun testEnterWithTrailingCommaAndWhitespaceBeforeLineBreakWithInvertedAlignWhenMultiline() { + doTypeTest( + '\n', + """ + |fun method( + | arg1: String, + |) {} + """, + """ + |fun method( + | arg1: String, + | + |) {} + """, + settingsWithInvertedAlignWhenMultiline + ) + } + + fun testSmartEnterBetweenOpeningAndClosingBracketsWithInvertedAlignWhenMultiline() { + doTypeTest( + '\n', + """ + |fun method() {} + """, + """ + |fun method( + | + |) {} + """, + settingsWithInvertedAlignWhenMultiline + ) + } + fun testAutoIndentInWhenClause() { doTypeTest( '\n',