返回 DeepSeek-Reasonix
workspacePathCopyMenuItems.tsx
根目录 / desktop / frontend / src / lib / workspacePathCopyMenuItems.tsx
1 import { Copy } from "lucide-react";
2 import type { FloatingMenuItem } from "../components/FloatingMenu";
3 import { writeClipboardText } from "./clipboard";
4
5 export const WORKSPACE_CONTEXT_MENU_FILE_HEIGHT = 280;
6 export const WORKSPACE_CONTEXT_MENU_REF_HEIGHT = 236;
7
8 export function workspacePathCopyMenuItems({
9 path,
10 resolveAbsolutePath,
11 isScopeCurrent,
12 close,
13 relativeLabel,
14 absoluteLabel,
15 }: {
16 path: string;
17 resolveAbsolutePath: () => Promise<string>;
18 isScopeCurrent: () => boolean;
19 close: () => void;
20 relativeLabel: string;
21 absoluteLabel: string;
22 }): FloatingMenuItem[] {
23 return [
24 {
25 icon: <Copy size={14} />,
26 label: relativeLabel,
27 onSelect: () => {
28 const relativePath = path.replace(/\/+$/, "");
29 close();
30 if (relativePath) void writeClipboardText(relativePath);
31 },
32 },
33 {
34 icon: <Copy size={14} />,
35 label: absoluteLabel,
36 onSelect: () => {
37 close();
38 void resolveAbsolutePath()
39 .then((absolutePath) => {
40 if (absolutePath && isScopeCurrent()) return writeClipboardText(absolutePath);
41 })
42 .catch(() => {
43 // The path may disappear between opening the menu and selecting it.
44 });
45 },
46 },
47 ];
48 }
49
49 lines Plain Text