fixed EA-56204 - IOOBE: SegmentArray.findSegmentIndex
authorEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Tue, 13 May 2014 10:03:20 +0000 (14:03 +0400)
committerEkaterina Tuzova <Ekaterina.Tuzova@jetbrains.com>
Tue, 13 May 2014 10:03:20 +0000 (14:03 +0400)
python/src/com/jetbrains/python/codeInsight/editorActions/moveUpDown/PyStatementMover.java

index b3264a65f36178fdae4fe3d5154063a509c2d4b9..65cd5e1a79ce9c74524b219614a893f8647391b4 100644 (file)
@@ -47,11 +47,13 @@ public class PyStatementMover extends LineMover {
     final Document document = editor.getDocument();
     final int lineNumber = document.getLineNumber(offset);
     int start = getLineStartSafeOffset(document, lineNumber);
-    int end = document.getLineEndOffset(lineNumber) - 1;
+    final int lineEndOffset = document.getLineEndOffset(lineNumber);
+    int end = lineEndOffset == 0 ? 0 : lineEndOffset - 1;
 
     if (selectionModel.hasSelection()) {
       start = selectionModel.getSelectionStart();
-      end = selectionModel.getSelectionEnd() - 1;
+      final int selectionEnd = selectionModel.getSelectionEnd();
+      end = selectionEnd == 0 ? 0 : selectionEnd - 1;
     }
     PsiElement elementToMove1 = PyUtil.findNonWhitespaceAtOffset(file, start);
     PsiElement elementToMove2 = PyUtil.findNonWhitespaceAtOffset(file, end);