Порівняти коміти

...
1 Коміти
Автор SHA1 Повідомлення Дата
l0ng-ai ca6deba8c0 fix(project): copy absolute Windows paths with backslashes
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:37:57 +08:00
5 змінених файлів з 34 додано та 6 видалено

No files matched your search

+1 -1
Переглянути файл
@@ -1446,7 +1446,7 @@ export function registerEditorActions(): () => void {
keyWhen: "editorFocus || !toolWindowFocus",
run: () => {
const p = ctrl.activePath();
if (p) copyEditorPath(p);
if (p) copyEditorPath(pathToCopy("absolute", p) ?? p);
},
},
{
+2 -1
Переглянути файл
@@ -70,6 +70,7 @@ import {
} from "./store";
import styles from "./SearchEverywhere.module.css";
import { isImeKey } from "@/platform/ime";
import { nativePath } from "@/platform/paths";
type SeScope = "allPlaces" | ProjectFileSet;
@@ -416,7 +417,7 @@ function SearchEverywhereDialog() {
{ label: "Open", run: () => activate(row) },
{ label: "Open to the Side", shortcut: formatBinding("Shift+Enter"), run: () => activate(row, true) },
{ kind: "separator" },
{ label: "Copy Path", run: () => copy(row.path) },
{ label: "Copy Path", run: () => copy(nativePath(row.path)) },
{ label: "Copy Path from Project Root", run: () => copy(row.rel) },
...(row.kind === "symbol" ? [{ label: "Copy Name", run: () => copy(row.name) }] : []),
...(row.kind === "file" || row.kind === "text"
+13
Переглянути файл
@@ -19,6 +19,19 @@ describe("shared copy path values", () => {
expect(pathToCopy("relative", "C:/p/src/a.ts", "C:/p")).toBe("src/a.ts");
});
it("writes absolute Windows paths with backslashes", () => {
expect(pathToCopy("absolute", "C:/work/shop/docs/api.md", "C:/work/shop")).toBe("C:\\work\\shop\\docs\\api.md");
expect(pathToCopy("absolute", "//server/share/a.ts", "//server/share")).toBe("\\\\server\\share\\a.ts");
expect(pathToCopy("absolute", "//?/UNC/server/share/a.ts", null)).toBe("\\\\server\\share\\a.ts");
expect(pathToCopy("absolute", "//?/C:/p/a.ts", null)).toBe("C:\\p\\a.ts");
// Outside the content root a relative copy falls back to the absolute path.
expect(pathToCopy("relative", "D:/other/a.ts", "C:/p")).toBe("D:\\other\\a.ts");
// Relative paths keep `/`, like IDEA's Path From Content Root.
expect(pathToCopy("relative", "C:/p/src/a.ts", "C:/p")).toBe("src/a.ts");
// Remote and POSIX paths stay as they are.
expect(pathToCopy("absolute", "/home/me/a.ts", "/home/me")).toBe("/home/me/a.ts");
});
it("uses the containing workspace folder as the content root", () => {
useProject.setState({ project: { root: "/workspace", workspace: { projects: ["/a", "/b"] } } as never });
expect(pathToCopy("relative", "/b/src/a.ts")).toBe("src/a.ts");
+8 -4
Переглянути файл
@@ -1,16 +1,20 @@
import { isSameOrInside } from "./paths";
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. */
/**
* 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 path;
if (kind === "absolute") return nativePath(path);
if (kind === "name") return basename(path);
if (kind === "source") {
const source = rootOfPath(path);
@@ -18,6 +22,6 @@ export function pathToCopy(
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 path;
if (!root || !isSameOrInside(path, root)) return nativePath(path);
return path.slice(root.length + (root.endsWith("/") ? 0 : 1)) || ".";
}
+10
Переглянути файл
@@ -21,6 +21,16 @@ export function ipcPath(p: string): string {
return DRIVE.test(path) || NETWORK.test(path) ? path.replace(/\\/g, "/") : path;
}
/**
* `p` (a path in the UI's `/`-separated form) as Windows writes it, for text the user pastes
* elsewhere: `C:/a/b` becomes `C:\a\b`, `//server/share/x` becomes `\\server\share\x`. Any
* other path (POSIX, remote) is returned as is.
*/
export function nativePath(p: string): string {
const path = p.replace(/^\/\/\?\/UNC\//i, "//").replace(/^\/\/\?\/(?=[A-Za-z]:\/)/, "");
return /^[A-Za-z]:\//.test(path) || /^\/\/[^/?.]/.test(path) ? path.replace(/\//g, "\\") : p;
}
const SHARE = /^[\\/]{2}/;
const SHARE_NAME = /^[\\/]{2}(?:\?[\\/]UNC[\\/])?([^\\/]+)[\\/]([^\\/]+)/i;