Don't extend to comments when a comment is being moved (KT-23461)
This commit is contained in:
+13
-6
@@ -228,7 +228,12 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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 start = sibling;
|
||||||
@Nullable PsiElement end = sibling;
|
@Nullable PsiElement end = sibling;
|
||||||
|
|
||||||
@@ -349,10 +354,12 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<PsiElement, PsiElement> extended = extendForSiblingComments(start, end, sibling, editor, down);
|
if (!(elementToCheck instanceof PsiComment)) {
|
||||||
if (extended != null) {
|
Pair<PsiElement, PsiElement> extended = extendForSiblingComments(start, end, sibling, editor, down);
|
||||||
start = extended.first;
|
if (extended != null) {
|
||||||
end = extended.second;
|
start = extended.first;
|
||||||
|
end = extended.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return start != null && end != null ? new LineRange(start, end, editor.getDocument()) : null;
|
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) {
|
if (elementToCheck instanceof KtExpression || elementToCheck instanceof PsiComment) {
|
||||||
return getExpressionTargetRange(editor, sibling, down);
|
return getExpressionTargetRange(editor, elementToCheck, sibling, down);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elementToCheck instanceof KtWhenEntry) {
|
if (elementToCheck instanceof KtWhenEntry) {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun foo() {
|
||||||
|
<caret>// Move me down
|
||||||
|
// 1
|
||||||
|
// 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// MOVE: down
|
||||||
|
fun foo() {
|
||||||
|
// 1
|
||||||
|
<caret>// Move me down
|
||||||
|
// 2
|
||||||
|
}
|
||||||
Generated
+5
@@ -849,6 +849,11 @@ public class MoveStatementTestGenerated extends AbstractMoveStatementTest {
|
|||||||
runTest("idea/testData/codeInsight/moveUpDown/expressions/closureWthoutSpaces2.kt");
|
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")
|
@TestMetadata("declaration1.kt")
|
||||||
public void testDeclaration1() throws Exception {
|
public void testDeclaration1() throws Exception {
|
||||||
runTest("idea/testData/codeInsight/moveUpDown/expressions/declaration1.kt");
|
runTest("idea/testData/codeInsight/moveUpDown/expressions/declaration1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user