From 9ed900e2bea1d794fa0730bdd101360ef3985a5a Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sat, 16 Nov 2013 20:33:49 -0800 Subject: [PATCH] Fix auto-indent for { --- .../jet/plugin/editor/KotlinTypedHandler.java | 2 +- .../jet/editor/TypedHandlerTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java b/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java index 89d57a5be61..39ba975a96d 100644 --- a/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java @@ -76,8 +76,8 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { if (previousElement instanceof LeafPsiElement && ((LeafPsiElement) previousElement).getElementType() == JetTokens.LONG_TEMPLATE_ENTRY_START) { editor.getDocument().insertString(offset, "}"); + return Result.STOP; } - return Result.STOP; } return Result.CONTINUE; diff --git a/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java b/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java index 998a88535cf..6eadd418582 100644 --- a/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java +++ b/idea/tests/org/jetbrains/jet/editor/TypedHandlerTest.java @@ -26,6 +26,30 @@ public class TypedHandlerTest extends LightCodeInsightTestCase { checkResultByText("val x = \"${}\""); } + public void testAutoIndentRightOpenBrace() throws Exception { + configureFromFileText("a.kt", + "fun test() {\n" + + "\n" + + "}"); + EditorTestUtil.performTypingAction(getEditor(), '{'); + checkResultByText( + "fun test() {\n" + + " {}\n" + + "}"); + } + + public void testAutoIndentLeftOpenBrace() throws Exception { + configureFromFileText("a.kt", + "fun test() {\n" + + " \n" + + "}"); + EditorTestUtil.performTypingAction(getEditor(), '{'); + checkResultByText( + "fun test() {\n" + + " {}\n" + + "}"); + } + public void testTypeStringTemplateStartWithCloseBraceAfter() throws Exception { configureFromFileText("a.kt", "fun foo() { \"$\" }"); EditorTestUtil.performTypingAction(getEditor(), '{');