void (final Project project, final Editor editor, final Surrounder surrounder, final PsiElement[] elements) { WriteAction.run(() -> PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument())); int col = editor.getCaretModel().getLogicalPosition().column; int line = editor.getCaretModel().getLogicalPosition().line; if (!editor.getCaretModel().supportsMultipleCarets()) { LogicalPosition pos = new LogicalPosition(0, 0); editor.getCaretModel().moveToLogicalPosition(pos); } if (surrounder.startInWriteAction()) { WriteCommandAction.runWriteCommandAction(project, CodeInsightBundle.message("surround.with.chooser.title"), null, () -> { TextRange range = surrounder.surroundElements(project, editor, elements); updateRange(project, editor, range, line, col); } ); } else { CommandProcessor.getInstance().executeCommand(project, () -> { TextRange range = ReadAction.compute(() -> surrounder.surroundElements(project, editor, elements)); updateRange(project, editor, range, line, col); }, CodeInsightBundle.message("surround.with.chooser.title"), null); } }