Insert paired brackets: insert space after right brace of nested lambda (KT-28098)
#KT-28098 Fixed
This commit is contained in:
committed by
Nikolay Krasko
parent
49d6bbbd6b
commit
ade51588f9
@@ -116,7 +116,8 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
||||
|
||||
int tokenBeforeBraceOffset = iterator.getStart();
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
|
||||
Document document = editor.getDocument();
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document);
|
||||
|
||||
PsiElement leaf = file.findElementAt(offset);
|
||||
if (leaf != null) {
|
||||
@@ -130,6 +131,14 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
||||
return Result.STOP;
|
||||
}
|
||||
}
|
||||
if (leaf.getText().equals("}")
|
||||
&& parent instanceof KtFunctionLiteral
|
||||
&& document.getLineNumber(offset) == document.getLineNumber(parent.getTextRange().getStartOffset())
|
||||
) {
|
||||
EditorModificationUtil.insertStringAtCaret(editor, "{} ", false, false);
|
||||
editor.getCaretModel().moveToOffset(offset + 1);
|
||||
return Result.STOP;
|
||||
}
|
||||
}
|
||||
|
||||
return Result.CONTINUE;
|
||||
|
||||
@@ -398,7 +398,13 @@ class TypedHandlerTest : LightCodeInsightTestCase() {
|
||||
" if (some.hello (12) {<caret>})\n" +
|
||||
"}"
|
||||
)
|
||||
|
||||
|
||||
fun testInsertSpaceAfterRightBraceOfNestedLambda() = doTypeTest(
|
||||
'{',
|
||||
"val t = Array(100) { Array(200) <caret>}",
|
||||
"val t = Array(100) { Array(200) {<caret>} }"
|
||||
)
|
||||
|
||||
fun testAutoInsertParenInStringLiteral() = doTypeTest(
|
||||
'(',
|
||||
"""fun f() { println("$dollar{f<caret>}") }""",
|
||||
|
||||
Reference in New Issue
Block a user