Skip to content

Commit c522580

Browse files
authored
fix: preserve selected public subfolder when opening terminal (#2003)
1 parent cc7bf73 commit c522580

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/lib/openFolder.js

Lines changed: 27 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,32 @@ 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 = /::/.test(url)
56+
? decodeURIComponent(docId || "")
57+
: docId || "";
58+
if (!cleanDocId) return "/public";
59+
if (cleanDocId.startsWith(publicDir)) {
60+
return cleanDocId.replace(publicDir, "/public") || "/public";
61+
}
62+
if (cleanDocId.startsWith("/public")) {
63+
return cleanDocId;
64+
}
65+
if (cleanDocId.startsWith("public:")) {
66+
const relativePath = cleanDocId.slice("public:".length);
67+
return relativePath ? Path.join("/public", relativePath) : "/public";
68+
}
69+
const relativePath = cleanDocId
70+
.replace(/^\/+/, "")
71+
.replace(/^public\//, "");
72+
return relativePath ? Path.join("/public", relativePath) : "/public";
73+
} catch (error) {
74+
console.warn(
75+
`Failed to parse public SAF URI for terminal conversion: ${url}`,
76+
);
77+
return "/public";
78+
}
5379
}
5480
const cleanUrl = url.replace(/^file:\/\//, "");
5581
if (cleanUrl.startsWith(publicDir)) {

0 commit comments

Comments
 (0)