From 073954937e73c2903d61a86980bc1aa65d7759ef Mon Sep 17 00:00:00 2001 From: bkellam Date: Sun, 21 Sep 2025 12:19:38 -0700 Subject: [PATCH] convert file match container to link --- .../searchResultsPanel/fileMatch.tsx | 40 +++++++++---------- .../searchResultsPanel/fileMatchContainer.tsx | 25 ------------ 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatch.tsx b/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatch.tsx index a24b8e45..3b1943ba 100644 --- a/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatch.tsx +++ b/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatch.tsx @@ -1,27 +1,22 @@ 'use client'; -import { useCallback } from "react"; 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/useBrowseNavigation"; +import { useDomain } from "@/hooks/useDomain"; interface FileMatchProps { match: SearchResultChunk; file: SearchResultFile; - onOpen: (startLineNumber: number, endLineNumber: number, isCtrlKeyPressed: boolean) => void; } export const FileMatch = ({ match, file, - onOpen: _onOpen, }: FileMatchProps) => { - const onOpen = useCallback((isCtrlKeyPressed: boolean) => { - const startLineNumber = match.contentStart.lineNumber; - const endLineNumber = match.content.trimEnd().split('\n').length + startLineNumber - 1; - - _onOpen(startLineNumber, endLineNumber, isCtrlKeyPressed); - }, [match.content, match.contentStart.lineNumber, _onOpen]); + const domain = useDomain(); // If it's just the title, don't show a code preview if (match.matchRanges.length === 0) { @@ -29,19 +24,24 @@ export const FileMatch = ({ } return ( -
{ - if (e.key !== "Enter") { - return; + 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, + } } - - onOpen(e.metaKey || e.ctrlKey); - }} - onClick={(e) => { - onOpen(e.metaKey || e.ctrlKey); - }} + })} title="open file: click, open file preview: cmd/ctrl + click" > {match.content} -
+ ); } \ No newline at end of file diff --git a/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatchContainer.tsx b/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatchContainer.tsx index 820521b9..b10d656a 100644 --- a/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatchContainer.tsx +++ b/packages/web/src/app/[domain]/search/components/searchResultsPanel/fileMatchContainer.tsx @@ -7,7 +7,6 @@ import { useMemo } from "react"; import { FileMatch } from "./fileMatch"; import { RepositoryInfo, SearchResultFile } from "@/features/search/types"; import { Button } from "@/components/ui/button"; -import { useBrowseNavigation } from "@/app/[domain]/browse/hooks/useBrowseNavigation"; export const MAX_MATCHES_TO_PREVIEW = 3; @@ -33,7 +32,6 @@ export const FileMatchContainer = ({ const matchCount = useMemo(() => { return file.chunks.length; }, [file]); - const { navigateToPath } = useBrowseNavigation(); const matches = useMemo(() => { const sortedMatches = file.chunks.sort((a, b) => { @@ -123,29 +121,6 @@ export const FileMatchContainer = ({ { - if (isCtrlKeyPressed) { - const matchIndex = matches.slice(0, index).reduce((acc, match) => { - return acc + match.matchRanges.length; - }, 0); - onOpenFilePreview(matchIndex); - } else { - navigateToPath({ - repoName: file.repository, - revisionName: file.branches?.[0] ?? 'HEAD', - path: file.fileName.text, - pathType: 'blob', - highlightRange: { - start: { - lineNumber: startLineNumber, - }, - end: { - lineNumber: endLineNumber, - } - } - }); - } - }} /> {(index !== matches.length - 1 || isMoreContentButtonVisible) && (