void (XExpression text) { myExpression = text; // set a dummy document immediately myEditor.getEditorTextField().setNewDocumentAndFileType(getFileType(text), new DocumentImpl(text.getExpression())); // schedule the real document creation ReadAction.nonBlocking(() -> createDocument(text)) .inSmartMode(getProject()) .finishOnUiThread(ModalityState.any(), document -> { myEditor.getEditorTextField().setNewDocumentAndFileType(getFileType(text), document); getEditorsProvider().afterEditorCreated(getEditor()); }) .coalesceBy(this) .submit(AppExecutorUtil.getAppExecutorService()); }