fixed PY-5200 Move statement: ineffective moving of nested if block

This commit is contained in:
Ekaterina Tuzova
2011-12-14 16:32:20 +04:00
parent 3741753179
commit a1e5d2ea44
5 changed files with 32 additions and 3 deletions

View File

@@ -349,9 +349,13 @@ public class StatementMover extends LineMover {
Pair<PyElement, PyElement> statementParts = getStatementParts(info, editor, file, down);
PyElement statementPart1 = statementParts.first;
PyElement statementPart2 = statementParts.second;
if (statementPart2 instanceof PyStatementPart)
myStatementPartToRemovePass = (PyStatementPart)statementParts.second;
if (statementPart2 instanceof PyStatementPart) {
PyStatementList stList = ((PyStatementPart)statementParts.second).getStatementList();
if (stList != null && stList.getStatements().length == 1 && stList.getStatements()[0] instanceof PyPassStatement ||
moveToEmptyLine) {
myStatementPartToRemovePass = (PyStatementPart)statementParts.second;
}
}
if (statementPart2 != null && statementPart1 != null && statementPart1.getParent() == statementPart2.getParent() ||
statementPart2 == statementPart1) return true;
return false;
@@ -415,6 +419,9 @@ public class StatementMover extends LineMover {
CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(myStatementListToAddPass);
}
if (myStatementToIncreaseIndent != null) {
if (!down && myStatementPartToRemovePass != null && myStatementToAddLinebreak == null) {
info.toMove2 = new LineRange(info.toMove2.startLine-1, info.toMove2.endLine);
}
increaseIndent(editor);
}
if (myStatementToDecreaseIndent != null) {

View File

@@ -0,0 +1,6 @@
if condition:
pass
elif other_condition:
pass
if another_on<caret>e: # <- move up here
a=1

View File

@@ -0,0 +1,7 @@
if condition:
pass
elif other_condition:
pass
if another_on<caret>e: # <- move up here
a=1

View File

@@ -0,0 +1,5 @@
if condition:
pass
elif other_condition:
if another_one: # <- move up here
a=1

View File

@@ -29,6 +29,10 @@ public class PyStatementMoverTest extends PyTestCase {
doTest();
}
public void testNestedIfUp() {
doTest();
}
public void testMoveDownOut() {
doTest();
}