diff --git a/platform/lang-impl/src/com/intellij/largeFilesEditor/editor/EditorModel.java b/platform/lang-impl/src/com/intellij/largeFilesEditor/editor/EditorModel.java index 7a71cf7a691e..84b209262b55 100644 --- a/platform/lang-impl/src/com/intellij/largeFilesEditor/editor/EditorModel.java +++ b/platform/lang-impl/src/com/intellij/largeFilesEditor/editor/EditorModel.java @@ -269,6 +269,7 @@ public class EditorModel { } if (isNeedToShowCaret) { + ensureTargetCaretPositionIsInFileBounds(pagesAmountInFile); targetVisiblePosition.set(targetCaretPosition.pageNumber, targetVisiblePosition.verticalScrollOffset); // we can't count the necessary offset at this stage } @@ -685,6 +686,15 @@ public class EditorModel { return false; } + private void ensureTargetCaretPositionIsInFileBounds(long pagesAmount) { + if (targetCaretPosition.pageNumber < 0) { + targetCaretPosition.set(0, 0); + } + else if (targetCaretPosition.pageNumber >= pagesAmount) { + targetCaretPosition.set(pagesAmount, 0); + } + } + private void normalizePagesInDocumentListEnding() { int visibleTargetPageIndex = tryGetIndexOfNeededPageInList(targetVisiblePosition.pageNumber); if (visibleTargetPageIndex == -1) { diff --git a/platform/lang-impl/src/com/intellij/largeFilesEditor/file/FileAdapter.java b/platform/lang-impl/src/com/intellij/largeFilesEditor/file/FileAdapter.java index b04e3d9f0186..6e76414bcf01 100644 --- a/platform/lang-impl/src/com/intellij/largeFilesEditor/file/FileAdapter.java +++ b/platform/lang-impl/src/com/intellij/largeFilesEditor/file/FileAdapter.java @@ -121,16 +121,12 @@ class FileAdapter { */ @NotNull String getPageText(long pageNumber) throws IOException { - randomAccessFileLock.lock(); try { - - /*DEBUG BEGIN*/ - //java.util.Random rand = new java.util.Random(System.currentTimeMillis()); - //if (true) try { Thread.sleep(rand.nextInt(100));} catch (InterruptedException e) {} - //if (rand.nextInt(10) < 1) throw new FileNotFoundException(); - //try { Thread.sleep(10);} catch (InterruptedException e) {} - /*DEBUG END*/ + long pagesAmount = getPagesAmount(); + if (pageNumber < 0 || pageNumber >= pagesAmount) { + throw new IllegalArgumentException("pageNumber=" + pageNumber + ", pagesAmount=" + pagesAmount); + } long minProbStartPos; long startByte;