void (Editor editor) { Document document = editor.getDocument(); CharSequence text = document.getImmutableCharSequence(); for (Caret caret : editor.getCaretModel().getAllCarets()) { int caretOffset = caret.getOffset(); caret.setSelection(CharArrayUtil.shiftForward(text, DocumentUtil.getLineStartOffset(caretOffset, document), " \t"), CharArrayUtil.shiftBackward(text, DocumentUtil.getLineEndOffset(caretOffset, document) - 1, " \t") + 1); } }