void (final Editor editor, final Document document, final PsiElement psiAtOffset, int caretOffset) { String text = document.getText(); String line = text.substring(0, caretOffset); int i = line.lastIndexOf('\n'); if (i > 0) { line = line.substring(i); } final String toInsert; if (PropertiesUtil.isUnescapedBackSlashAtTheEnd(line)) { toInsert = "\n "; } else { final IElementType elementType = psiAtOffset == null ? null : psiAtOffset.getNode().getElementType(); if (elementType == PropertiesTokenTypes.VALUE_CHARACTERS) { if (text.charAt(caretOffset) == ' ' || text.charAt(caretOffset) == '\t') { // escape the whitespace on the next line like "\ " toInsert = "\\\n \\"; } else { toInsert = "\\\n "; } } else if (elementType == PropertiesTokenTypes.END_OF_LINE_COMMENT && "#!".indexOf(document.getText().charAt(caretOffset)) == -1) { toInsert = "\n#"; } else { toInsert = "\n"; } } document.insertString(caretOffset, toInsert); caretOffset+=toInsert.length(); editor.getCaretModel().moveToOffset(caretOffset); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); editor.getSelectionModel().removeSelection(); }