void (@NotNull final Editor editor, @NotNull Caret caret, final DataContext dataContext) { if (editor.isViewer() || !EditorModificationUtil.requestWriting(editor)) return; if (!(editor.getDocument() instanceof DocumentEx document)) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, caret, dataContext); } return; } Project project = editor.getProject(); PsiFile psiFile = project == null ? null : PsiDocumentManager.getInstance(project).getPsiFile(document); if (psiFile == null) { if (myOriginalHandler != null) { myOriginalHandler.execute(editor, caret, dataContext); } return; } LogicalPosition caretPosition = caret.getLogicalPosition(); int startLine = caretPosition.line; int endLine = startLine + 1; if (caret.hasSelection()) { startLine = document.getLineNumber(caret.getSelectionStart()); endLine = document.getLineNumber(caret.getSelectionEnd()); if (document.getLineStartOffset(endLine) == caret.getSelectionEnd()) endLine--; } if (endLine >= document.getLineCount()) return; int lineCount = endLine - startLine; int line = startLine; ((ApplicationImpl)ApplicationManager.getApplication()).runWriteActionWithCancellableProgressInDispatchThread( LangBundle.message("progress.title.join.lines"), project, null, indicator -> { indicator.setIndeterminate(false); JoinLineProcessor processor = new JoinLineProcessor(document, psiFile, line, indicator); processor.process(editor, caret, lineCount); }); }