Result ( @NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffset, final @NotNull Ref<Integer> caretAdvance, @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) { Result res = shouldSkipWithResult(file, editor, dataContext); if (res != null) { return res; } final Document document = editor.getDocument(); int caret = editor.getCaretModel().getOffset(); final int lineNumber = document.getLineNumber(caret); final int lineStartOffset = document.getLineStartOffset(lineNumber); final int previousLineStartOffset = lineNumber > 0 ? document.getLineStartOffset(lineNumber - 1) : lineStartOffset; final EditorHighlighter highlighter = editor.getHighlighter(); final HighlighterIterator iterator = highlighter.createIterator(caret - 1); final IElementType type = getNonWhitespaceElementType(iterator, lineStartOffset, previousLineStartOffset); final CharSequence editorCharSequence = document.getCharsSequence(); final CharSequence lineIndent = editorCharSequence.subSequence(lineStartOffset, EditorActionUtil.findFirstNonSpaceOffsetOnTheLine(document, lineNumber)); // Enter in line comment if (type == myLineCommentType) { final String restString = editorCharSequence.subSequence(caret, document.getLineEndOffset(lineNumber)).toString(); if (!StringUtil.isEmptyOrSpaces(restString)) { final String linePrefix = lineIndent + myLineCommentPrefix; EditorModificationUtilEx.insertStringAtCaret(editor, "\n" + linePrefix); editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, linePrefix.length())); return Result.Stop; } else if (iterator.getStart() < lineStartOffset) { EditorModificationUtilEx.insertStringAtCaret(editor, "\n" + lineIndent); return Result.Stop; } } if (!myWorksWithFormatter && LanguageFormatting.INSTANCE.forLanguage(myLanguage) != null) { return Result.Continue; } else { if (myIndentTokens.contains(type)) { final String newIndent = getNewIndent(file, document, lineIndent); EditorModificationUtilEx.insertStringAtCaret(editor, "\n" + newIndent); return Result.Stop; } EditorModificationUtilEx.insertStringAtCaret(editor, "\n" + lineIndent); editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, calcLogicalLength(editor, lineIndent))); return Result.Stop; } }