'use client'; import { useCallback, useMemo } from "react"; import { SearchResultFile, SearchResultChunk } from "@/features/search/types"; import { base64Decode } from "@/lib/utils"; import { LightweightCodeHighlighter } from "@/app/[domain]/components/lightweightCodeHighlighter"; interface FileMatchProps { match: SearchResultChunk; file: SearchResultFile; onOpen: (startLineNumber: number, endLineNumber: number, isCtrlKeyPressed: boolean) => void; } export const FileMatch = ({ match, file, onOpen: _onOpen, }: FileMatchProps) => { const content = useMemo(() => { return base64Decode(match.content); }, [match.content]); const onOpen = useCallback((isCtrlKeyPressed: boolean) => { const startLineNumber = match.contentStart.lineNumber; const endLineNumber = content.trimEnd().split('\n').length + startLineNumber - 1; _onOpen(startLineNumber, endLineNumber, isCtrlKeyPressed); }, [content, match.contentStart.lineNumber, _onOpen]); // If it's just the title, don't show a code preview if (match.matchRanges.length === 0) { return null; } return (
{ if (e.key !== "Enter") { return; } onOpen(e.metaKey || e.ctrlKey); }} onClick={(e) => { onOpen(e.metaKey || e.ctrlKey); }} title="open file: click, open file preview: cmd/ctrl + click" > {content}
); }