Файли
openidea/src/platform/copyPath.ts
T
l0ng-ai 26aabf5229 fix(project): copy absolute Windows paths with backslashes (#5808)
Copy Absolute Path returned the UI's /-separated form, so C:/work/a.md went to the clipboard and cmd, robocopy and the Explorer address bar rejected it. pathToCopy now writes absolute drive and UNC paths with backslashes (new nativePath, the inverse of ipcPath); paths relative to a content or source root keep /. The editor's Absolute Path action and Search Everywhere's Copy Path go through the same conversion.

Fixes #5805
2026-11-25 15:38:15 +08:00

28 рядки
1.1 KiB
TypeScript

import { isSameOrInside, nativePath } from "./paths";
import { basename, projectFolder, useProject } from "./project";
import { projectRelative, rootOfPath } from "./projectRoots";
export type PathKind = "absolute" | "relative" | "name" | "source";
/**
* Shared by the project view, editor tabs and the caret's copy chooser. An absolute path is
* written the platform's way (`C:\\a\\b` on Windows) so it pastes into the shell and file
* dialogs; paths relative to a root keep `/`.
*/
export function pathToCopy(
kind: PathKind,
path: string,
root: string | null = projectFolder(useProject.getState().project, path)?.root ?? null,
): string | null {
if (kind === "absolute") return nativePath(path);
if (kind === "name") return basename(path);
if (kind === "source") {
const source = rootOfPath(path);
const relative = projectRelative(path);
if (!source || source.kind === "excluded" || relative === null) return null;
return relative.slice(source.path.length + (source.path ? 1 : 0)) || ".";
}
if (!root || !isSameOrInside(path, root)) return nativePath(path);
return path.slice(root.length + (root.endsWith("/") ? 0 : 1)) || ".";
}