sourcebot/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatch.tsx
Brendan Kellam 4ebe4e0475
Some checks failed
Publish to ghcr / build (linux/amd64, blacksmith-4vcpu-ubuntu-2404) (push) Has been cancelled
Publish to ghcr / build (linux/arm64, blacksmith-8vcpu-ubuntu-2204-arm) (push) Has been cancelled
Publish to ghcr / merge (push) Has been cancelled
chore(worker,web): Repo indexing stability improvements + perf improvements to web (#563)
2025-10-18 16:31:22 -07:00

58 lines
No EOL
1.8 KiB
TypeScript

'use client';
import { SearchResultFile, SearchResultChunk } from "@/features/search/types";
import { LightweightCodeHighlighter } from "@/app/[domain]/components/lightweightCodeHighlighter";
import Link from "next/link";
import { getBrowsePath } from "@/app/[domain]/browse/hooks/utils";
import { useDomain } from "@/hooks/useDomain";
interface FileMatchProps {
match: SearchResultChunk;
file: SearchResultFile;
}
export const FileMatch = ({
match,
file,
}: FileMatchProps) => {
const domain = useDomain();
// If it's just the title, don't show a code preview
if (match.matchRanges.length === 0) {
return null;
}
return (
<Link
tabIndex={0}
className="cursor-pointer focus:ring-inset focus:ring-4 bg-background hover:bg-editor-lineHighlight"
href={getBrowsePath({
repoName: file.repository,
revisionName: file.branches?.[0] ?? 'HEAD',
path: file.fileName.text,
pathType: 'blob',
domain,
highlightRange: {
start: {
lineNumber: match.contentStart.lineNumber,
},
end: {
lineNumber: match.content.trimEnd().split('\n').length + match.contentStart.lineNumber - 1,
}
}
})}
title="open file: click, open file preview: cmd/ctrl + click"
>
<LightweightCodeHighlighter
language={file.language}
highlightRanges={match.matchRanges}
lineNumbers={true}
lineNumbersOffset={match.contentStart.lineNumber}
renderWhitespace={true}
>
{match.content}
</LightweightCodeHighlighter>
</Link>
);
}