Files
paseo/packages/app/src/utils/explorer-paths.ts
T
ca2b633286 feat: add file manager context actions (#3027)
* feat(app): add file manager context actions

* fix: reshape file context actions

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
2026-08-10 18:18:23 +02:00

40 lines
1.1 KiB
TypeScript

import { isAbsolutePath } from "./path";
interface BuildAbsoluteExplorerPathInput {
workspaceRoot: string;
entryPath: string;
}
export function buildAbsoluteExplorerPath({
workspaceRoot,
entryPath,
}: BuildAbsoluteExplorerPathInput): string {
const normalizedWorkspaceRoot = workspaceRoot.trim().replace(/[\\/]+$/, "");
const normalizedEntryPath = entryPath.trim();
if (!normalizedWorkspaceRoot) {
return normalizedEntryPath;
}
if (!normalizedEntryPath || normalizedEntryPath === ".") {
return normalizedWorkspaceRoot;
}
if (isAbsolutePath(normalizedEntryPath)) {
return normalizedEntryPath;
}
const separator = normalizedWorkspaceRoot.includes("\\") ? "\\" : "/";
const segments = normalizedEntryPath.split(/[\\/]+/).filter(Boolean);
if (segments.length === 0) {
return normalizedWorkspaceRoot;
}
return `${normalizedWorkspaceRoot}${separator}${segments.join(separator)}`;
}
export function parentExplorerPath(entryPath: string): string {
const separatorIndex = entryPath.lastIndexOf("/");
return separatorIndex > 0 ? entryPath.slice(0, separatorIndex) : ".";
}