LogicalPosition (final PsiFile file, final Editor editor) { if (editor.getSelectionModel().hasSelection()) return null; final LogicalPosition caretPos = editor.getCaretModel().getLogicalPosition(); if (caretPos.column == 0) { return null; } if (!isWhitespaceBeforeCaret(editor)) { return null; } // Determine indent size CommonCodeStyleSettings.IndentOptions fileIndentOptions = CodeStyle.getIndentOptions(file); int indent = fileIndentOptions.INDENT_SIZE; if (!fileIndentOptions.isOverrideLanguageOptions()) { Language language = getLanguageAtCursorPosition(file, editor); if (language != file.getLanguage()) { indent = CodeStyle.getSettings(file).getLanguageIndentOptions(language).INDENT_SIZE; } } // Decrease column down to indentation * n int column = indent > 0 ? (caretPos.column - 1) / indent * indent : 0; return new LogicalPosition(caretPos.line, column); }