fixed PY-5268 Move statement: breaks code in case of indented one-line compound statements

This commit is contained in:
Ekaterina Tuzova
2012-03-22 17:14:48 +04:00
parent c4928a6bfc
commit 32220e98fa
5 changed files with 24 additions and 2 deletions
@@ -35,6 +35,7 @@ public class StatementMover extends LineMover {
@Nullable private PsiElement myStatementToMove;
@Nullable private PyStatementPart myStatementPartToRemovePass;
private boolean moveToEmptyLine = false;
private boolean theSameLevel;
private void init(@NotNull final Editor editor, @NotNull final MoveInfo info, final boolean down) {
LineRange range = StatementUpDownMover.getLineRangeFromSelection(editor);
@@ -105,7 +106,7 @@ public class StatementMover extends LineMover {
expandLineRangeToStatement(info, editor, down, file);
//is move from one part of compound statement to another
boolean theSameLevel = isTheSameIndentLevel(info, editor, file, down);
theSameLevel = isTheSameIndentLevel(info, editor, file, down);
//check we move statement into compound or out of compound
if (isMoveOut(info, editor, file, down)) {
@@ -425,7 +426,8 @@ public class StatementMover extends LineMover {
PyStatementWithElse statementWithElse = PsiTreeUtil.getParentOfType(myStatementToAddLinebreak, PyStatementWithElse.class);
if (statementWithElse != null && statementWithElse.getParent() instanceof PyFile) indent = "\n";
if (whiteSpace instanceof PsiWhiteSpace) indent += whiteSpace.getText();
if (down) indent += StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
if (down || theSameLevel) indent += StringUtil.repeatSymbol(' ', indentOptions.INDENT_SIZE);
if (theSameLevel) info.toMove = info.toMove2;
editor.getDocument().insertString(textRange.getStartOffset(), indent);
}
// add pass statement if needed
+5
View File
@@ -0,0 +1,5 @@
def a():
if True: a = 1
else:
c = <caret>1
b = 2
@@ -0,0 +1,5 @@
def a():
if True: a = 1
else:
b = 2
c = 1
@@ -0,0 +1,6 @@
def a():
if True:
a = 1
else:
c = 1
b = 2
@@ -49,6 +49,10 @@ public class PyStatementMoverTest extends PyTestCase {
doTest();
}
public void testIndentedOneLine() { //PY-5268
doTest();
}
public void testComment() { //PY-5270
doTest();
}