Skip to content

Commit eb0f4d7

Browse files
committed
fix: preserve selected public subfolder when opening terminal
1 parent cc7bf73 commit eb0f4d7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/lib/openFolder.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import escapeStringRegexp from "escape-string-regexp";
1414
import FileBrowser from "pages/fileBrowser";
1515
import helpers from "utils/helpers";
1616
import Path from "utils/Path";
17+
import Uri from "utils/Uri";
1718
import Url from "utils/Url";
1819
import constants from "./constants";
1920
import * as FileList from "./fileList";
@@ -49,7 +50,28 @@ const isTerminalAccessiblePath = (url = "") => {
4950
const convertToProotPath = (url = "") => {
5051
const { alpineRoot, publicDir } = getTerminalPaths();
5152
if (isAcodeTerminalPublicSafUri(url)) {
52-
return "/public";
53+
try {
54+
const { docId } = Uri.parse(url);
55+
const cleanDocId = decodeURIComponent(docId || "");
56+
if (!cleanDocId) return "/public";
57+
if (cleanDocId.startsWith(publicDir)) {
58+
return cleanDocId.replace(publicDir, "/public") || "/public";
59+
}
60+
if (cleanDocId.startsWith("/public")) {
61+
return cleanDocId;
62+
}
63+
if (cleanDocId.startsWith("public:")) {
64+
const relativePath = cleanDocId.slice("public:".length);
65+
return relativePath ? Path.join("/public", relativePath) : "/public";
66+
}
67+
const relativePath = cleanDocId.replace(/^\/+/, "");
68+
return relativePath ? Path.join("/public", relativePath) : "/public";
69+
} catch (error) {
70+
console.warn(
71+
`Failed to parse public SAF URI for terminal conversion: ${url}`,
72+
);
73+
return "/public";
74+
}
5375
}
5476
const cleanUrl = url.replace(/^file:\/\//, "");
5577
if (cleanUrl.startsWith(publicDir)) {

0 commit comments

Comments
 (0)