void (final @Nullable String text) { CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> { LineSeparator separator = LINE_SEPARATOR_KEY.get(myDocument); if (separator == null) { separator = detectLineSeparators(myDocument, text); } LINE_SEPARATOR_KEY.set(myDocument, separator); myDocument.replaceString(0, myDocument.getTextLength(), normalize(text, separator)); Editor editor = getEditor(); if (editor != null) { final CaretModel caretModel = editor.getCaretModel(); if (caretModel.getOffset() >= myDocument.getTextLength()) { caretModel.moveToOffset(myDocument.getTextLength()); } } }), null, null, UndoConfirmationPolicy.DEFAULT, getDocument()); }