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