int () { int indexOfPage = documentOfPagesModel.tryGetIndexOfNeededPageInList(targetCaretPosition.pageNumber); int targetCaretOffsetInDocument; if (indexOfPage != -1) { targetCaretOffsetInDocument = getSymbolOffsetToStartOfPage(indexOfPage) + targetCaretPosition.symbolOffsetInPage; } else if (targetCaretPosition.symbolOffsetInPage == 0 && targetCaretPosition.pageNumber == documentOfPagesModel.getLastPage().getPageNumber() + 1) { targetCaretOffsetInDocument = getSymbolOffsetToStartOfPage(documentOfPagesModel.getPagesAmount()); } else { return -1; } int docLength = documentOfPagesModel.getDocument().getTextLength(); if (targetCaretOffsetInDocument >= 0) { return Math.min(targetCaretOffsetInDocument, docLength); } else { LOG.warn("[Large File Editor Subsystem] EditorModel.tryGetTargetCaretOffsetInDocument():" + " Invalid targetCaretPosition state." + " targetCaretPosition.pageNumber=" + targetCaretPosition.pageNumber + " targetCaretPosition.symbolOffsetInPage=" + targetCaretPosition.symbolOffsetInPage + " targetCaretOffsetInDocument=" + targetCaretOffsetInDocument + " document.getTextLength()=" + docLength); } return -1; }