Файли
openidea/src/platform/copyPath.ts
T
l0ng-ai 0630ed0729 feat(editor): clipboard: whole-line paste, paste history dialog, copy path chooser, escape and imports on paste (#2014)
Whole-line copies and cuts paste above the caret line from every paste entry point (shortcut, menu, history, plain text), including a copied blank line. Paste from History opens a dialog with filter, multi-select, delete and preview. Copy Path/Reference (⇧⌘C) opens a chooser for absolute path, file name, content-root/source-root paths, path with line and reference. Text pasted into a string literal is escaped (Smart Keys setting; Paste as Plain Text bypasses it), and missing imports are added after a paste (Auto Import setting: Ask / Always / Never).
2026-11-08 06:13:21 +08:00

24 рядки
975 B
TypeScript

import { isSameOrInside } 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. */
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 === "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 path;
return path.slice(root.length + (root.endsWith("/") ? 0 : 1)) || ".";
}