fixed PY-11198 Move Statement Up/Down near dictionary expression unexpectedly merges statements

This commit is contained in:
Ekaterina Tuzova
2014-09-08 19:16:48 +04:00
parent 7985e36080
commit 7fd1c618c0
6 changed files with 50 additions and 8 deletions
@@ -108,7 +108,6 @@ public class PyStatementMover extends LineMover {
if (moveOutsideFile(document, lineNumber)) return null;
int lineEndOffset = document.getLineEndOffset(lineNumber);
final int startOffset = document.getLineStartOffset(lineNumber);
lineEndOffset = startOffset != lineEndOffset ? lineEndOffset - 1 : lineEndOffset;
final PyStatementList statementList = getStatementList(elementToMove);
@@ -278,11 +277,23 @@ public class PyStatementMover extends LineMover {
private static PsiElement getDestinationElement(@NotNull final PsiElement elementToMove, @NotNull final Document document,
int lineEndOffset, boolean down) {
PsiElement destination = elementToMove.getContainingFile().findElementAt(lineEndOffset);
if (destination == null) return null;
if (destination instanceof PsiComment) return destination;
PsiElement destination = PyUtil.findPrevAtOffset(elementToMove.getContainingFile(), lineEndOffset, PsiWhiteSpace.class);
PsiElement sibling = down ? PsiTreeUtil.getNextSiblingOfType(elementToMove, PyStatement.class) :
PsiTreeUtil.getPrevSiblingOfType(elementToMove, PyStatement.class);
PsiTreeUtil.getPrevSiblingOfType(elementToMove, PyStatement.class);
if (destination == null) {
if (elementToMove instanceof PyClass) {
destination = sibling;
}
else if (elementToMove instanceof PyFunction) {
if (!(sibling instanceof PyClass))
destination = sibling;
else destination = null;
}
else {
return null;
}
}
if (destination instanceof PsiComment) return destination;
if (elementToMove instanceof PyClass) {
destination = sibling;
}
@@ -1394,8 +1394,8 @@ public class PyUtil {
@Nullable
public static PsiElement findPrevAtOffset(PsiFile psiFile, int caretOffset, Class... toSkip) {
PsiElement element = psiFile.findElementAt(caretOffset);
if (element == null || caretOffset < 0) {
PsiElement element;
if (caretOffset < 0) {
return null;
}
int lineStartOffset = 0;
+9
View File
@@ -0,0 +1,9 @@
a = {
'c': 99999
}
print "Hello, there."
a = {
'b': 1,
'c': 2
}
print <caret>a['c']
@@ -0,0 +1,9 @@
a = {
'c': 99999
}
print "Hello, there."
a = {
'b': 1,
'c': 2
}
print a['c']
@@ -0,0 +1,9 @@
a = {
'c': 99999
}
print "Hello, there."
print a['c']
a = {
'b': 1,
'c': 2
}
@@ -260,7 +260,11 @@ public class PyStatementMoverTest extends PyTestCase {
doTest();
}
public void testOutsideFromDict() { //PY-11595
public void testOutsideFromDict() {
doTest();
}
public void testSameLevelAsDict() {
doTest();
}