void (Page page, Project project) { pagesInDocument.add(page); symbolOffsetToEndOfPage.add( (symbolOffsetToEndOfPage.isEmpty() ? 0 : symbolOffsetToEndOfPage.get(symbolOffsetToEndOfPage.size() - 1)) + page.getText().length()); runAsWriteAction( project, myDocument.getTextLength() == 0 ? () -> myDocument.setText(page.getText()) : () -> myDocument.insertString(myDocument.getTextLength(), page.getText())); }