MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / PathHeader

Function PathHeader

packages/web/src/app/(app)/components/pathHeader.tsx:52–320  ·  view source on GitHub ↗
({
    repo,
    path,
    pathHighlightRange,
    revisionName,
    branchDisplayName = revisionName,
    isBranchDisplayNameVisible = !!branchDisplayName,
    branchDisplayTitle,
    pathType = 'blob',
    isCodeHostIconVisible = true,
    isFileIconVisible = true,
    repoNameClassName,
}: FileHeaderProps)

Source from the content-addressed store, hash-verified

50}
51
52export const PathHeader = ({
53 repo,
54 path,
55 pathHighlightRange,
56 revisionName,
57 branchDisplayName = revisionName,
58 isBranchDisplayNameVisible = !!branchDisplayName,
59 branchDisplayTitle,
60 pathType = 'blob',
61 isCodeHostIconVisible = true,
62 isFileIconVisible = true,
63 repoNameClassName,
64}: FileHeaderProps) => {
65 const info = getCodeHostInfoForRepo({
66 name: repo.name,
67 codeHostType: repo.codeHostType,
68 displayName: repo.displayName,
69 externalWebUrl: repo.externalWebUrl,
70 });
71
72 const { toast } = useToast();
73 const containerRef = useRef<HTMLDivElement>(null);
74 const breadcrumbsRef = useRef<HTMLDivElement>(null);
75 const [visibleSegmentCount, setVisibleSegmentCount] = useState<number | null>(null);
76 // Create breadcrumb segments from file path
77 const breadcrumbSegments = useMemo(() => {
78 const pathParts = path.split('/').filter(Boolean);
79 const segments: BreadcrumbSegment[] = [];
80
81 let currentPath = '';
82 pathParts.forEach((part, index) => {
83 currentPath = currentPath ? `${currentPath}/${part}` : part;
84 const isLastSegment = index === pathParts.length - 1;
85
86 // Calculate highlight range for this segment if it exists
87 let segmentHighlight: { from: number; to: number } | undefined;
88 if (pathHighlightRange) {
89 const segmentStart = path.indexOf(part, currentPath.length - part.length);
90 const segmentEnd = segmentStart + part.length;
91
92 // Check if highlight overlaps with this segment
93 if (pathHighlightRange.from < segmentEnd && pathHighlightRange.to > segmentStart) {
94 segmentHighlight = {
95 from: Math.max(0, pathHighlightRange.from - segmentStart),
96 to: Math.min(part.length, pathHighlightRange.to - segmentStart)
97 };
98 }
99 }
100
101 segments.push({
102 name: part,
103 fullPath: currentPath,
104 isLastSegment,
105 highlightRange: segmentHighlight
106 });
107 });
108
109 return segments;

Callers

nothing calls this directly

Calls 8

getCodeHostInfoForRepoFunction · 0.90
useToastFunction · 0.90
cnFunction · 0.90
getBrowsePathFunction · 0.90
truncateShaFunction · 0.90
measureSegmentsFunction · 0.85
toastFunction · 0.85

Tested by

no test coverage detected