mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-11654 Move Statement: IOE at com.intellij.openapi.editor.impl.DocumentImpl.d
This commit is contained in:
+3
-19
@@ -103,7 +103,7 @@ public class PyStatementMover extends LineMover {
|
||||
|
||||
final int offset = down ? elementToMove.getTextRange().getEndOffset() : elementToMove.getTextRange().getStartOffset();
|
||||
int lineNumber = down ? document.getLineNumber(offset) + 1 : document.getLineNumber(offset) - 1;
|
||||
if (moveOutsideFile(elementToMove, document, lineNumber)) return null;
|
||||
if (moveOutsideFile(document, lineNumber)) return null;
|
||||
int lineEndOffset = document.getLineEndOffset(lineNumber);
|
||||
final int startOffset = document.getLineStartOffset(lineNumber);
|
||||
lineEndOffset = startOffset != lineEndOffset ? lineEndOffset - 1 : lineEndOffset;
|
||||
@@ -141,24 +141,8 @@ public class PyStatementMover extends LineMover {
|
||||
return new LineRange(startLine, endLine + 1);
|
||||
}
|
||||
|
||||
private static boolean moveOutsideFile(@NotNull final PsiElement elementToMove, @NotNull final Document document, int lineNumber) {
|
||||
if (lineNumber < 0) return true;
|
||||
if (lineNumber >= document.getLineCount()) {
|
||||
final int elementOffset = elementToMove.getTextRange().getStartOffset();
|
||||
final int lineStartOffset = document.getLineStartOffset(document.getLineNumber(elementOffset));
|
||||
final int insertIndex = lineNumber < 0 ? 0 : document.getTextLength();
|
||||
if (elementOffset != lineStartOffset) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
document.insertString(insertIndex, "\n");
|
||||
PsiDocumentManager.getInstance(elementToMove.getProject()).commitAllDocuments();
|
||||
}
|
||||
});
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
return false;
|
||||
private static boolean moveOutsideFile(@NotNull final Document document, int lineNumber) {
|
||||
return lineNumber < 0 || lineNumber >= document.getLineCount();
|
||||
}
|
||||
|
||||
private static boolean moveToEmptyLine(@NotNull final PsiElement elementToMove, boolean down) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
if value is not None:
|
||||
if not False or value <= 2:
|
||||
print "h<caret>ere"
|
||||
print "h<caret>ere"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if value is not None:
|
||||
print "here"
|
||||
if not False or value <= 2:
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
for item in range(1,
|
||||
3):
|
||||
b = 2<caret>
|
||||
b = 2<caret>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
b = 2<caret>
|
||||
for item in range(1,
|
||||
3):
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
if True:
|
||||
<caret><selection> a = 2
|
||||
b = 3</selection>
|
||||
b = 3</selection>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<caret><selection>a = 2
|
||||
b = 3</selection>
|
||||
if True:
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -4,4 +4,4 @@ def test(a, b=1):
|
||||
else:
|
||||
for n in range(10):
|
||||
|
||||
<caret> print(b)
|
||||
<caret> print(b)
|
||||
|
||||
@@ -3,4 +3,4 @@ if condition:
|
||||
elif other_condition:
|
||||
if another_one:
|
||||
if T<caret>rue: a = 1 # <- move statement up here
|
||||
else: b = 2
|
||||
else: b = 2
|
||||
|
||||
@@ -4,4 +4,4 @@ elif other_condition:
|
||||
if T<caret>rue: a = 1 # <- move statement up here
|
||||
else: b = 2
|
||||
if another_one:
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -4,4 +4,4 @@ try:
|
||||
except:
|
||||
print(zoo(0).foo(2))
|
||||
except:
|
||||
zoo<caret>(3)
|
||||
zoo<caret>(3)
|
||||
|
||||
@@ -5,4 +5,4 @@ try:
|
||||
print(zoo(0).foo(2))
|
||||
zoo(3)
|
||||
except:
|
||||
pass
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user