fixed PY-13868 Move statement on a comment inside a dict deletes the dict

This commit is contained in:
Ekaterina Tuzova
2014-09-08 17:55:30 +04:00
parent e0fd4f52a3
commit 877fae21f2
5 changed files with 24 additions and 5 deletions
@@ -119,10 +119,6 @@ public class PyStatementMover extends LineMover {
final int startLine = document.getLineNumber(start);
final int endLine = document.getLineNumber(end);
if (elementToMove instanceof PsiComment && destination instanceof PsiComment) {
return new LineRange(lineNumber, lineNumber + 1);
}
if (elementToMove instanceof PyClass || elementToMove instanceof PyFunction) {
PyElement scope = statementList == null ? (PyElement)elementToMove.getContainingFile() : statementList;
if (destination != null)
@@ -137,6 +133,11 @@ public class PyStatementMover extends LineMover {
scopeRange = moveInto(elementToMove, file, editor, down, lineEndOffset);
if (scopeRange != null) return scopeRange;
if (elementToMove instanceof PsiComment && ( PsiTreeUtil.isAncestor(destination, elementToMove, true)) ||
destination instanceof PsiComment) {
return new LineRange(lineNumber, lineNumber + 1);
}
final PyElement scope = statementList == null ? (PyElement)elementToMove.getContainingFile() : statementList;
if ((elementToMove instanceof PyClass) || (elementToMove instanceof PyFunction))
return new ScopeRange(scope, scope.getFirstChild(), !down, true);
@@ -185,7 +186,6 @@ public class PyStatementMover extends LineMover {
if (sibling != null) {
final PyStatementList list = sibling.getStatementList();
assert list != null;
return new ScopeRange(list, down ? list.getFirstChild() : list.getLastChild(), !addBefore);
}
else {
+5
View File
@@ -0,0 +1,5 @@
a = {
1:1,
# te<caret>st
2:2
}
@@ -0,0 +1,5 @@
a = {
1:1,
2:2
# te<caret>st
}
@@ -0,0 +1,5 @@
a = {
# te<caret>st
1:1,
2:2
}
@@ -260,6 +260,10 @@ public class PyStatementMoverTest extends PyTestCase {
doTest();
}
public void testOutsideFromDict() { //PY-11595
doTest();
}
public void testWith() { // PY-5202
try {
setLanguageLevel(LanguageLevel.PYTHON27);