feat(files): add Copy Relative Path to file context menu (#932)
Add "Copy Relative Path" menu item below "Copy Path" in the file tree context menu. Uses the existing getDisplayPath helper to compute a path relative to the project root, which is more useful when sharing file references in AI chat or commit messages.
This commit is contained in:
@@ -284,6 +284,7 @@ const isHtmlFile = (path: string): boolean => {
|
|||||||
|
|
||||||
interface FileRowProps {
|
interface FileRowProps {
|
||||||
node: FileNode;
|
node: FileNode;
|
||||||
|
root: string;
|
||||||
isExpanded: boolean;
|
isExpanded: boolean;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
@@ -307,6 +308,7 @@ interface FileRowProps {
|
|||||||
|
|
||||||
const FileRow: React.FC<FileRowProps> = ({
|
const FileRow: React.FC<FileRowProps> = ({
|
||||||
node,
|
node,
|
||||||
|
root,
|
||||||
isExpanded,
|
isExpanded,
|
||||||
isActive,
|
isActive,
|
||||||
isMobile,
|
isMobile,
|
||||||
@@ -420,6 +422,19 @@ const FileRow: React.FC<FileRowProps> = ({
|
|||||||
}}>
|
}}>
|
||||||
<RiFileCopyLine className="mr-2 h-4 w-4" /> Copy Path
|
<RiFileCopyLine className="mr-2 h-4 w-4" /> Copy Path
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
const relativePath = getDisplayPath(root, node.path) || node.path;
|
||||||
|
void copyTextToClipboard(relativePath).then((result) => {
|
||||||
|
if (result.ok) {
|
||||||
|
toast.success('Relative path copied');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toast.error('Copy failed');
|
||||||
|
});
|
||||||
|
}}>
|
||||||
|
<RiFileCopy2Line className="mr-2 h-4 w-4" /> Copy Relative Path
|
||||||
|
</DropdownMenuItem>
|
||||||
{!isDir && downloadFile && (
|
{!isDir && downloadFile && (
|
||||||
<DropdownMenuItem onClick={(e) => {
|
<DropdownMenuItem onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -1648,6 +1663,7 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
)}
|
)}
|
||||||
<FileRow
|
<FileRow
|
||||||
node={node}
|
node={node}
|
||||||
|
root={root}
|
||||||
isExpanded={isExpanded}
|
isExpanded={isExpanded}
|
||||||
isActive={isActive}
|
isActive={isActive}
|
||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
|
|||||||
Reference in New Issue
Block a user