TextRange (Editor editor) { return ReadAction.compute(() -> { List<Caret> carets = editor.getCaretModel().getAllCarets(); return carets.get(0).getSelectionRange().union(carets.get(carets.size() - 1).getSelectionRange()); }); }