diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java index c7ecb17d65e..d1af53f8fca 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/KotlinExpressionMover.java @@ -228,7 +228,12 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover { } @Nullable - private static LineRange getExpressionTargetRange(@NotNull Editor editor, @NotNull PsiElement sibling, boolean down) { + private static LineRange getExpressionTargetRange( + @NotNull Editor editor, + @NotNull PsiElement elementToCheck, + @NotNull PsiElement sibling, + boolean down + ) { @Nullable PsiElement start = sibling; @Nullable PsiElement end = sibling; @@ -349,10 +354,12 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover { } } - Pair extended = extendForSiblingComments(start, end, sibling, editor, down); - if (extended != null) { - start = extended.first; - end = extended.second; + if (!(elementToCheck instanceof PsiComment)) { + Pair extended = extendForSiblingComments(start, end, sibling, editor, down); + if (extended != null) { + start = extended.first; + end = extended.second; + } } return start != null && end != null ? new LineRange(start, end, editor.getDocument()) : null; @@ -448,7 +455,7 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover { } if (elementToCheck instanceof KtExpression || elementToCheck instanceof PsiComment) { - return getExpressionTargetRange(editor, sibling, down); + return getExpressionTargetRange(editor, elementToCheck, sibling, down); } if (elementToCheck instanceof KtWhenEntry) { diff --git a/idea/testData/codeInsight/moveUpDown/expressions/comments.kt b/idea/testData/codeInsight/moveUpDown/expressions/comments.kt new file mode 100644 index 00000000000..c3bf93c4e88 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/comments.kt @@ -0,0 +1,6 @@ +// MOVE: down +fun foo() { + // Move me down + // 1 + // 2 +} diff --git a/idea/testData/codeInsight/moveUpDown/expressions/comments.kt.after b/idea/testData/codeInsight/moveUpDown/expressions/comments.kt.after new file mode 100644 index 00000000000..6b55855e9a8 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/expressions/comments.kt.after @@ -0,0 +1,6 @@ +// MOVE: down +fun foo() { + // 1 + // Move me down + // 2 +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java index 9465a983569..83b9ca288c9 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/MoveStatementTestGenerated.java @@ -849,6 +849,11 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest { runTest("idea/testData/codeInsight/moveUpDown/expressions/closureWthoutSpaces2.kt"); } + @TestMetadata("comments.kt") + public void testComments() throws Exception { + runTest("idea/testData/codeInsight/moveUpDown/expressions/comments.kt"); + } + @TestMetadata("declaration1.kt") public void testDeclaration1() throws Exception { runTest("idea/testData/codeInsight/moveUpDown/expressions/declaration1.kt");