EA-206288 [large file] Add ensuring that requested page number is in valid bounds

GitOrigin-RevId: d0bea3ded7022c1966d38745607c999f4d8affe9
This commit is contained in:
Vladimir.Petrenko
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent 90e915819b
commit a5679f67cd
2 changed files with 14 additions and 8 deletions
@@ -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) {
@@ -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;