fixed PY-5197 Move statement: inconsistent skipping of empty lines

This commit is contained in:
Ekaterina Tuzova
2011-12-02 12:45:03 +01:00
parent 72760de60a
commit ef2640a510
7 changed files with 28 additions and 2 deletions
@@ -88,6 +88,7 @@ public class StatementMover extends LineMover {
info.toMove2 = new LineRange(myStatementToMove);
}
if (isMoveToCompound(info, editor, file, down)) {
if (isMoveToEmptyLine(editor, info)) return true;
myStatementToIncreaseIndent = myStatementToMove;
if (!down)
info.toMove2 = new LineRange(myStatementToMove);
@@ -157,7 +158,9 @@ public class StatementMover extends LineMover {
info.toMove = range;
info.toMove2 = new LineRange(nearLine, nearLine + 1);
if (isMoveToEmptyLine(editor, info)) return;
// if try to move to the function or to the class
int offset2 = getLineStartSafeOffset(doc, info.toMove2.startLine);
PsiElement element2 = file.findElementAt(offset2);
if (element2 != null) {
@@ -185,6 +188,15 @@ public class StatementMover extends LineMover {
}
}
}
private boolean isMoveToEmptyLine(Editor editor, MoveInfo info) {
Document document = editor.getDocument();
if (document.getLineCount() > info.toMove2.endLine) {
String lineToMoveTo = document.getText(new TextRange(getLineStartSafeOffset(document, info.toMove2.startLine), getLineStartSafeOffset(document, info.toMove2.endLine)));
if (StringUtil.isEmptyOrSpaces(lineToMoveTo)) return true;
}
return false;
}
/**
* main indent logic
-1
View File
@@ -1,6 +1,5 @@
if condition1:
pass
if condi<caret>tion:
test1()
else:
@@ -1,6 +1,5 @@
if condition1:
pass
if condition:
test1()
else:
+4
View File
@@ -0,0 +1,4 @@
if True:
a = 1
b =<caret> 2
@@ -0,0 +1,4 @@
if True:
a = 1
b = 2
@@ -0,0 +1,4 @@
if True:
a = 1
b = 2
@@ -111,4 +111,8 @@ public class PyStatementMoverTest extends PyTestCase {
public void testOneLineCompound() { // PY-5198
doTest();
}
public void testEmptyLine() { // PY-5197
doTest();
}
}