public static boolean isCaretInsideSelection(@Nullable Caret caret) {
    return ReadAction.compute(() -> caret != null &&
           caret.hasSelection() &&
           caret.getOffset() >= caret.getSelectionStart() &&
           caret.getOffset() <= caret.getSelectionEnd());
  }
public static boolean isCaretInsideSelection(@Nullable Caret caret)