public static boolean isValidOffset(int offset, @NotNull Document document) {
    return offset >= 0 && offset <= document.getTextLength();
  }
public static boolean isValidOffset(int offset, @NotNull Document document)