fixed PY-5201 Move statement: changes code logic on moving one-line compound statement outside nested one

This commit is contained in:
Ekaterina Tuzova
2011-12-02 15:57:17 +01:00
parent 6004deefb3
commit 1de2fbaba1
5 changed files with 30 additions and 2 deletions
@@ -339,8 +339,13 @@ public class StatementMover extends LineMover {
getCurrentSettings().getIndentOptions(PythonFileType.INSTANCE);
assert indentOptions != null;
final Document document = editor.getDocument();
TextRange textRange = myStatementToDecreaseIndent.getTextRange();
document.deleteString(textRange.getStartOffset()-indentOptions.INDENT_SIZE, textRange.getStartOffset());
final int startLine = editor.offsetToLogicalPosition(myStatementToDecreaseIndent.getTextRange().getStartOffset()).line;
final int endLine = editor.offsetToLogicalPosition(myStatementToDecreaseIndent.getTextRange().getEndOffset()).line;
for (int line = startLine; line <= endLine; ++line) {
final int offset = document.getLineStartOffset(line);
document.deleteString(offset, offset + indentOptions.INDENT_SIZE);
}
myStatementToDecreaseIndent = null;
}
@@ -0,0 +1,6 @@
if condition:
pass
elif other_condition:
if another_one:
if T<caret>rue: a = 1 # <- move statement up here
else: b = 2
@@ -0,0 +1,6 @@
if condition:
pass
elif other_condition:
if another_one:
if T<caret>rue: a = 1 # <- move statement up here
else: b = 2
@@ -0,0 +1,7 @@
if condition:
pass
elif other_condition:
if T<caret>rue: a = 1 # <- move statement up here
else: b = 2
if another_one:
pass
@@ -121,6 +121,10 @@ public class PyStatementMoverTest extends PyTestCase {
doTest();
}
public void testOneLineCompoundOutside() { // PY-5201
doTest();
}
public void testWith() { // PY-5202
try {
setLanguageLevel(LanguageLevel.PYTHON27);