void (Project project) { if (pagesInDocument.size() > 0) { int indexOfLastPage = pagesInDocument.size() - 1; Page lastPage = pagesInDocument.get(indexOfLastPage); pagesInDocument.remove(indexOfLastPage); symbolOffsetToEndOfPage.remove(indexOfLastPage); runAsWriteAction( project, () -> myDocument.deleteString( myDocument.getTextLength() - lastPage.getText().length(), myDocument.getTextLength())); } }