more improvements for python statement mover

This commit is contained in:
alexey.ivanov
2010-05-11 16:53:06 +04:00
parent 0f5aa4541a
commit 03762a6f9d
4 changed files with 27 additions and 12 deletions
@@ -224,7 +224,7 @@ public class StatementMover extends LineMover {
final PyStatementList statementList = parentStatementPart.getStatementList();
assert statementList != null;
if (down) {
final PyStatementPart nextStatementPart = PsiTreeUtil.getNextSiblingOfType(statementList.getParent(), PyStatementPart.class);
PyStatementPart nextStatementPart = PsiTreeUtil.getNextSiblingOfType(statementList.getParent(), PyStatementPart.class);
if (nextStatementPart != null) {
info.toMove2 = new LineRange(range.endLine, range.endLine + 1);
myStatementListToRemovePass = nextStatementPart.getStatementList();
@@ -241,15 +241,20 @@ public class StatementMover extends LineMover {
if (nextStatement instanceof PyFunction || nextStatement instanceof PyClass) {
return false;
}
if (nextStatement == null) {
continue;
if (nextStatement != null) {
break;
}
break;
}
final int startLine = editor.offsetToLogicalPosition(parent.getTextRange().getEndOffset()).line;
final int endLine = editor.offsetToLogicalPosition(nextStatement.getTextRange().getEndOffset()).line;
info.toMove2 = new LineRange(startLine + 1, endLine + 1);
calculateIndent(editor, statementList, nextStatement);
nextStatementPart = PsiTreeUtil.getChildOfType(nextStatement, PyStatementPart.class);
if (nextStatementPart != null) {
calculateIndent(editor, statementList, nextStatementPart.getStatementList(), down);
}
else {
calculateIndent(editor, statementList, nextStatement, down);
}
myElementsToChangeIndent = statements;
}
}
@@ -294,7 +299,7 @@ public class StatementMover extends LineMover {
if (startLineNumber != endLineNumber) {
info.toMove2 = new LineRange(startLineNumber, startLineNumber + 1);
myStatementListToRemovePass = statementPart.getStatementList();
calculateIndent(editor, range.firstElement, myStatementListToRemovePass);
calculateIndent(editor, range.firstElement, myStatementListToRemovePass, down);
myElementsToChangeIndent = statements;
}
}
@@ -302,10 +307,17 @@ public class StatementMover extends LineMover {
}
private void calculateIndent(final Editor editor, final PsiElement firstElement, final PsiElement secondElement) {
private void calculateIndent(final Editor editor, final PsiElement firstElement, final PsiElement secondElement, final boolean down) {
final PsiFile file = firstElement.getContainingFile();
final int firstIndent = getIndent(editor, file, editor.offsetToLogicalPosition(firstElement.getTextRange().getStartOffset()).line);
final int secondIndent = getIndent(editor, file, editor.offsetToLogicalPosition(secondElement.getTextRange().getEndOffset()).line);
int line;
if (down) {
line = editor.offsetToLogicalPosition(secondElement.getTextRange().getStartOffset()).line;
}
else {
line = editor.offsetToLogicalPosition(secondElement.getTextRange().getEndOffset()).line;
}
final int secondIndent = getIndent(editor, file, line);
myIndentLevel = (secondIndent - firstIndent) >> 2;
}
+2 -1
View File
@@ -6,7 +6,8 @@ class A:
if d:
self.bar()
c<caret> = 3
a = 2
if c:
a = 2
def bar(self):
pass
+3 -2
View File
@@ -5,8 +5,9 @@ class A:
if c:
if d:
self.bar()
a = 2
c = 3
if c:
a = 2
c = 3
def bar(self):
pass
+2 -1
View File
@@ -6,7 +6,8 @@ class A:
if d:
c = 3
self.bar()
a = 2
if c:
a = 2
def bar(self):
pass