static int restoreCaretOffset(@NotNull RangeMarker caretRangeMarker, int offset) {
    if (caretRangeMarker.isValid()) {
      if (caretRangeMarker.getStartOffset() <= offset && caretRangeMarker.getEndOffset() >= offset) {
        return offset;
      }
      return caretRangeMarker.getEndOffset();
    }
    return offset;
  }
static int restoreCaretOffset(@NotNull RangeMarker caretRangeMarker, int offset)