void (@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { Document document = editor.getDocument(); if (EditorUtil.isPasswordEditor(editor)) { caret.setSelection(0, document.getTextLength()); return; } int lineNumber = caret.getLogicalPosition().line; int caretOffset = caret.getOffset(); if (lineNumber >= document.getLineCount()) { return; } boolean camel = editor.getSettings().isCamelWords(); List<TextRange> ranges = new ArrayList<>(); int textLength = document.getTextLength(); if (caretOffset == textLength) caretOffset--; if (caretOffset < 0) return; SelectWordUtil.addWordOrLexemeSelection(camel, editor, caretOffset, ranges); // add whole line selection int line = document.getLineNumber(caretOffset); ranges.add(new TextRange(document.getLineStartOffset(line), document.getLineEndOffset(line))); final TextRange selectionRange = new TextRange(caret.getSelectionStart(), caret.getSelectionEnd()); TextRange minimumRange = new TextRange(0, document.getTextLength()); for (TextRange range : ranges) { if (range.contains(selectionRange) && !range.equals(selectionRange)) { if (minimumRange.contains(range)) { minimumRange = range; } } } caret.setSelection(minimumRange.getStartOffset(), minimumRange.getEndOffset()); }