@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
45
45
class KotlinMultilineStringEnterHandler : EnterHandlerDelegateAdapter () {
46
46
private var wasInMultilineString: Boolean = false
47
47
private var whiteSpaceAfterCaret: String = " "
48
+ private var isInBrace = false
48
49
49
50
override fun preprocessEnter (
50
51
file : PsiFile , editor : Editor , caretOffset : Ref <Int >, caretAdvance : Ref <Int >, dataContext : DataContext ,
@@ -70,7 +71,7 @@ class KotlinMultilineStringEnterHandler : EnterHandlerDelegateAdapter() {
70
71
71
72
val ch1 = text[offset - 1 ]
72
73
val ch2 = text[offset]
73
- val isInBrace = (ch1 == ' (' && ch2 == ' )' ) || (ch1 == ' {' && ch2 == ' }' )
74
+ isInBrace = (ch1 == ' (' && ch2 == ' )' ) || (ch1 == ' {' && ch2 == ' }' )
74
75
if (! isInBrace || ! CodeInsightSettings .getInstance().SMART_INDENT_ON_ENTER ) {
75
76
return Result .Continue
76
77
}
@@ -118,11 +119,8 @@ class KotlinMultilineStringEnterHandler : EnterHandlerDelegateAdapter() {
118
119
val wasSingleLine = literal.text.indexOf(" \n " ) == literal.text.lastIndexOf(" \n " ) // Only one '\n' in the string after insertion
119
120
val lines = literal.text.split(" \n " )
120
121
121
- val inBraces = (prevLine.endsWith(" {" ) && nextLine.trim().startsWith(" }" )) ||
122
- (prevLine.endsWith(" (" ) && nextLine.trim().startsWith(" )" ))
123
-
124
122
val literalOffset = literal.textRange.startOffset
125
- if (wasSingleLine || (lines.size == 3 && inBraces )) {
123
+ if (wasSingleLine || (lines.size == 3 && isInBrace )) {
126
124
val shouldUseTrimIndent = hasTrimIndentCallInChain || (marginChar == null && lines.first().trim() == MULTILINE_QUOTE )
127
125
val newMarginChar: Char? = if (shouldUseTrimIndent) null else (marginChar ? : DEFAULT_TRIM_MARGIN_CHAR )
128
126
@@ -141,7 +139,7 @@ class KotlinMultilineStringEnterHandler : EnterHandlerDelegateAdapter() {
141
139
caretMarker.isGreedyToRight = true
142
140
}
143
141
144
- if (inBraces ) {
142
+ if (isInBrace ) {
145
143
// Move closing bracket under same indent
146
144
forceIndent(caretOffset() + 1 , indentSize, newMarginChar, document, settings)
147
145
}
@@ -175,7 +173,7 @@ class KotlinMultilineStringEnterHandler : EnterHandlerDelegateAdapter() {
175
173
176
174
if (marginCharToInsert == null || ! currentLine.trimStart().startsWith(marginCharToInsert)) {
177
175
val indentLength = when {
178
- inBraces -> settings.indentLength(nextLine)
176
+ isInBrace -> settings.indentLength(nextLine)
179
177
! isPrevLineFirst -> settings.indentLength(prevLine)
180
178
else -> settings.indentLength(prevLine) + settings.marginIndent
181
179
}
@@ -192,7 +190,7 @@ class KotlinMultilineStringEnterHandler : EnterHandlerDelegateAdapter() {
192
190
// Insert same indent after margin char that previous line has
193
191
document.insertString(caretOffset(), wsAfterMargin)
194
192
195
- if (inBraces ) {
193
+ if (isInBrace ) {
196
194
val nextLineOffset = document.getLineStartOffset(prevLineNumber + 2 )
197
195
forceIndent(nextLineOffset, 0 , null , document, settings)
198
196
document.insertString(nextLineOffset, (marginCharToInsert?.toString() ? : " " ) + wsAfterMargin)
0 commit comments