boolean (@NotNull PsiWhiteSpace psiWhiteSpace, int cursorPosition, @Nullable Caret caret, @NotNull Editor editor) { if (!AdvancedSettings.getBoolean("editor.selection.expand-whitespaces")) return false; TextRange selectionRange = caret != null && caret.hasSelection() ? caret.getSelectionRange() : null; if (selectionRange != null && !psiWhiteSpace.getTextRange().contains(selectionRange)) return false; int startOffset = selectionRange == null ? cursorPosition : selectionRange.getStartOffset(); Character charBeforeStartOffset = getCharBeforeCursorInPsiElement(psiWhiteSpace, startOffset); if (charBeforeStartOffset != null && isExpandableWhiteSpace(charBeforeStartOffset)) return true; int endOffset = selectionRange == null ? cursorPosition : selectionRange.getEndOffset(); Character charBeforeEndOffset = getCharBeforeCursorInPsiElement(psiWhiteSpace, endOffset); Character charAfterEndOffset = getCharAfterCursorInPsiElement(psiWhiteSpace, endOffset); if (charAfterEndOffset != null && isExpandableWhiteSpace(charAfterEndOffset)) return true; if (charBeforeEndOffset != null && isExpandableWhiteSpace(charBeforeEndOffset) && charAfterEndOffset != null && Character.isWhitespace(charAfterEndOffset)) { return true; } return false; }