Elffuss BraidHub

kikocis/continue public

8eb3ae7b8d16 · 1.6 KiBRawPermalink
1import { RangeInFile } from "core";
2import { findUriInDirs, getUriPathBasename } from "core/util/uri";
3import { useContext } from "react";
4import { v4 as uuidv4 } from "uuid";
5import { IdeMessengerContext } from "../../context/IdeMessenger";
6import FileIcon from "../FileIcon";
7import { ToolTip } from "../gui/Tooltip";
8
9interface FilenameLinkProps {
10 rif: RangeInFile;
11}
12
13function FilenameLink({ rif }: FilenameLinkProps) {
14 const ideMessenger = useContext(IdeMessengerContext);
15
16 function onClick() {
17 ideMessenger.post("showLines", {
18 filepath: rif.filepath,
19 startLine: rif.range.start.line,
20 endLine: rif.range.end.line,
21 });
22 }
23
24 const id = uuidv4();
25
26 let relPathOrBasename = "";
27 try {
28 const { relativePathOrBasename } = findUriInDirs(
29 rif.filepath,
30 window.workspacePaths ?? [],
31 );
32 relPathOrBasename = relativePathOrBasename;
33 } catch (e) {
34 return <span>{getUriPathBasename(rif.filepath)}</span>;
35 }
36
37 return (
38 <>
39 <span
40 data-tooltip-id={id}
41 data-tooltip-delay-show={500}
42 className="mx-[0.1em] mb-[0.15em] inline-flex cursor-pointer items-center gap-0.5 rounded-md pr-[0.2em] align-middle hover:ring-1"
43 onClick={onClick}
44 >
45 <FileIcon filename={rif.filepath} height="20px" width="20px" />
46 <span className="mb-0.5 align-baseline underline underline-offset-2">
47 {getUriPathBasename(rif.filepath)}
48 </span>
49 </span>
50 <ToolTip id={id} place="top">
51 {"/" + relPathOrBasename}
52 </ToolTip>
53 </>
54 );
55}
56
57export default FilenameLink;