mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
fixed PY-5200 Move statement: ineffective moving of nested if block
This commit is contained in:
@@ -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) {
|
||||
|
||||
6
python/testData/mover/nestedIfUp.py
Normal file
6
python/testData/mover/nestedIfUp.py
Normal file
@@ -0,0 +1,6 @@
|
||||
if condition:
|
||||
pass
|
||||
elif other_condition:
|
||||
pass
|
||||
if another_on<caret>e: # <- move up here
|
||||
a=1
|
||||
7
python/testData/mover/nestedIfUp_afterDown.py
Normal file
7
python/testData/mover/nestedIfUp_afterDown.py
Normal file
@@ -0,0 +1,7 @@
|
||||
if condition:
|
||||
pass
|
||||
elif other_condition:
|
||||
pass
|
||||
|
||||
if another_on<caret>e: # <- move up here
|
||||
a=1
|
||||
5
python/testData/mover/nestedIfUp_afterUp.py
Normal file
5
python/testData/mover/nestedIfUp_afterUp.py
Normal file
@@ -0,0 +1,5 @@
|
||||
if condition:
|
||||
pass
|
||||
elif other_condition:
|
||||
if another_one: # <- move up here
|
||||
a=1
|
||||
@@ -29,6 +29,10 @@ public class PyStatementMoverTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNestedIfUp() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMoveDownOut() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user