code: public IndexRange getStyleRangeAtPosition(int position) {
          Position pos = styles.offsetToPosition(position, Backward);
          int start = position - pos.getMinor();
          int end = start + styles.getStyleSpan(pos.getMajor()).getLength();
          return new IndexRange(start, end);
      }
docs: Returns the range of homogeneous style that includes the given position.
  If {@code position} points to a boundary between two styled ranges,
  then the range preceding {@code position} is returned.