Fix move when multi-line elements have shared lines
This commit is contained in:
@@ -109,6 +109,33 @@ public abstract class AbstractJetUpDownMover extends LineMover {
|
||||
return endLine - startLine;
|
||||
}
|
||||
|
||||
protected static int getElementLine(PsiElement element, Editor editor, boolean first) {
|
||||
if (element == null) return -1;
|
||||
|
||||
Document doc = editor.getDocument();
|
||||
TextRange spaceRange = element.getTextRange();
|
||||
|
||||
return first ? doc.getLineNumber(spaceRange.getStartOffset()) : doc.getLineNumber(spaceRange.getEndOffset());
|
||||
}
|
||||
|
||||
protected static PsiElement getLastNonWhiteSiblingInLine(@Nullable PsiElement element, @NotNull Editor editor, boolean down) {
|
||||
if (element == null) return null;
|
||||
|
||||
int line = getElementLine(element, editor, down);
|
||||
|
||||
PsiElement lastElement = element;
|
||||
while (true) {
|
||||
if (lastElement == null) return null;
|
||||
PsiElement sibling = firstNonWhiteSibling(lastElement, down);
|
||||
if (getElementLine(sibling, editor, down) == line) {
|
||||
lastElement = sibling;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
return lastElement;
|
||||
}
|
||||
|
||||
private static boolean checkCommentAtBlockBound(PsiElement blockElement, PsiElement comment, JetBlockExpression block) {
|
||||
return PsiTreeUtil.isAncestor(block, blockElement, true) && comment instanceof PsiComment;
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
|
||||
LineRange sourceRange = getSourceRange(firstDecl, lastDecl, editor, oldRange);
|
||||
if (sourceRange == null) return false;
|
||||
|
||||
PsiElement sibling = firstNonWhiteSibling(sourceRange, down);
|
||||
PsiElement sibling = getLastNonWhiteSiblingInLine(firstNonWhiteSibling(sourceRange, down), editor, down);
|
||||
|
||||
// Either reached last sibling, or jumped over multi-line whitespace
|
||||
if (sibling == null) {
|
||||
|
||||
@@ -476,7 +476,7 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
LineRange sourceRange = getSourceRange(firstElement, lastElement, editor, oldRange);
|
||||
if (sourceRange == null) return false;
|
||||
|
||||
PsiElement sibling = adjustSibling(editor, sourceRange, info, down);
|
||||
PsiElement sibling = getLastNonWhiteSiblingInLine(adjustSibling(editor, sourceRange, info, down), editor, down);
|
||||
|
||||
// Either reached last sibling, or jumped over multi-line whitespace
|
||||
if (sibling == null) return true;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ <caret>val foo = 1
|
||||
println("foo=")
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo() {
|
||||
/*
|
||||
*
|
||||
*/ <caret>val foo = 1
|
||||
|
||||
println("foo=")
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
<caret>println("foo=")
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo() {
|
||||
|
||||
<caret>println("foo=")
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
println("foo=")
|
||||
<caret>println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: up
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
<caret>println(foo) /*
|
||||
*
|
||||
*/
|
||||
println("foo=")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ <caret>val foo = 1
|
||||
println("foo=")
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo() {
|
||||
|
||||
println("foo=")
|
||||
/*
|
||||
*
|
||||
*/ <caret>val foo = 1
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
<caret>println("foo=")
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
println(foo) /*
|
||||
*
|
||||
*/
|
||||
<caret>println("foo=")
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
println("foo=")
|
||||
<caret>println(foo) /*
|
||||
*
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MOVE: down
|
||||
|
||||
fun foo() {
|
||||
|
||||
/*
|
||||
*
|
||||
*/ val foo = 1
|
||||
println("foo=")
|
||||
|
||||
<caret>println(foo) /*
|
||||
*
|
||||
*/
|
||||
}
|
||||
+30
@@ -912,6 +912,36 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/lambda3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multilineComment1.kt")
|
||||
public void testMultilineComment1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/multilineComment1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multilineComment2.kt")
|
||||
public void testMultilineComment2() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/multilineComment2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multilineComment3.kt")
|
||||
public void testMultilineComment3() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/multilineComment3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multilineComment4.kt")
|
||||
public void testMultilineComment4() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/multilineComment4.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multilineComment5.kt")
|
||||
public void testMultilineComment5() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/multilineComment5.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multilineComment6.kt")
|
||||
public void testMultilineComment6() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/multilineComment6.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("outOfClosure1.kt")
|
||||
public void testOutOfClosure1() throws Exception {
|
||||
doTestExpression("idea/testData/codeInsight/moveUpDown/expressions/outOfClosure1.kt");
|
||||
|
||||
Reference in New Issue
Block a user