Skip to content

Commit e3cc6bb

Browse files
committed
fix: path inconsistencies and tests
1 parent 5d6c0d1 commit e3cc6bb

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

src/project/WorkingSetView.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,40 +1017,49 @@ define(function (require, exports, module) {
10171017
let filePath = $li.data(_FILE_KEY).fullPath;
10181018
const io = externalProjectFiles.indexOf(filePath);
10191019
if (io !== -1) {
1020+
const displayPath = Phoenix.app.getDisplayPath(filePath);
10201021
let dirPath = path.dirname(filePath);
1021-
// this will be displayed on hover
1022-
const displayPath = Phoenix.app.getDisplayPath(dirPath);
1023-
1024-
let separator;
1025-
if (Phoenix.isNativeApp) {
1026-
separator = brackets.platform === "win" ? "\\" : "/";
1022+
// this will be displayed on hover GetDisplayPath returns
1023+
// windows: C://some/path , linux/mac: /some/path
1024+
// a relative path of the form `folder/file.txt` (no-leading slash) for fs access paths- /mnt/paths
1025+
// or virtual path if its a browser indexed db - backed path like /fs/virtual/path
1026+
const displayDirPath = Phoenix.app.getDisplayPath(dirPath);
1027+
1028+
let sep;
1029+
if (Phoenix.isNativeApp && brackets.platform === "win") {
1030+
sep = "\\";
10271031
} else {
1028-
separator = "/";
1032+
sep = "/";
10291033
}
10301034

1031-
let dirSplit = displayPath.split(separator);
1035+
// Split the path and filter out empty segments
1036+
let dirSplit = displayDirPath.split(sep).filter(segment => segment !== '');
10321037

1033-
let truncatedPath = displayPath; // truncatedPath value will be shown in the UI
1038+
let truncatedPath = displayDirPath; // truncatedPath value will be shown in the UI
10341039
if (dirSplit.length > 3) {
1035-
let rootDirName;
1036-
1037-
if (Phoenix.isNativeApp) {
1038-
// Desktop app paths
1039-
// dirSplit[0] maybe empty sometimes for absolute paths on Linux/Mac eg: "/root/fs/path/to/file"
1040-
rootDirName = dirSplit[0] ? dirSplit[0] : dirSplit[1];
1040+
const rootDirName = dirSplit[0];
1041+
const secondLastSegment = dirSplit[dirSplit.length - 2];
1042+
const fileName = dirSplit[dirSplit.length - 1];
1043+
1044+
if (Phoenix.isNativeApp && brackets.platform === "win") {
1045+
// Eg: C:\\long\path\to\file.txt - > C:\\...\to\file.txt
1046+
truncatedPath = `${rootDirName}:${sep}${sep}\u2026${sep}${secondLastSegment}${sep}${fileName}`;
1047+
} else if (Phoenix.isNativeApp) {
1048+
// an absolute path of the form /abs/path/to/file in linux/mac desktop
1049+
// Eg: /application/path/to/file.txt - > /application/.../to/file.txt
1050+
truncatedPath = `${sep}${rootDirName}${sep}\u2026${sep}${secondLastSegment}${sep}${fileName}`;
1051+
} else if (!Phoenix.isNativeApp && !displayDirPath.startsWith('/')){
1052+
// browser fs access path: `folder/file.txt` (no-leading slash) fs access paths- /mnt/paths
1053+
// Eg: opened/folder/path/to/file.txt - > opened/.../to/file.txt (no-leading slash)
1054+
truncatedPath = `${rootDirName}${sep}\u2026${sep}${secondLastSegment}${sep}${fileName}`;
10411055
} else {
1042-
// Browser paths - handle different formats
1043-
if (displayPath.startsWith('/')) {
1044-
// Internal/default projects: /fs/path/to/file
1045-
// dirSplit[0] will be empty due to leading '/'
1046-
rootDirName = dirSplit[1] || dirSplit[0];
1047-
} else {
1048-
// User-opened system folders: path/to/file (no leading '/')
1049-
rootDirName = dirSplit[0];
1050-
}
1056+
//this is an internal indexed db backed virtual path. This can only happen if we allow virtual
1057+
// project locations from one project to be opened in another. So just print the trim path
1058+
// path in this case. In future, when we add this support, the get display path fn should be
1059+
// modified to give somethings like what we do for fs access path.
1060+
// Eg: /application/path/to/file.txt - > /application/.../to/file.txt
1061+
truncatedPath = `${sep}${rootDirName}${sep}\u2026${sep}${secondLastSegment}${sep}${fileName}`;
10511062
}
1052-
1053-
truncatedPath = rootDirName + separator + "\u2026" + separator + dirSplit[dirSplit.length - 1];
10541063
}
10551064

10561065
const $dir = $(`<span title='${displayPath}' class='directory'/>`)

test/spec/WorkingSetView-integ-test.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ define(function (require, exports, module) {
3737
describe("mainview:WorkingSetView", function () {
3838

3939
var testPath = SpecRunnerUtils.getTestPath("/spec/WorkingSetView-test-files"),
40-
externalProjectTestPath = SpecRunnerUtils.getTestPath("/spec/MainViewManager-test-files"),
40+
externalProjectTestPath = SpecRunnerUtils.getTestPath("/spec/MainViewFactory-test-files/css"),
4141
testWindow,
4242
workingSetListItemCount;
4343

@@ -230,8 +230,19 @@ define(function (require, exports, module) {
230230
// empty the working set
231231
await testWindow.closeAllFiles();
232232
workingSetListItemCount = 0;
233+
const virtualPath = externalProjectTestPath + "/tablet.css";
234+
const hoverFullPath = Phoenix.app.getDisplayPath(virtualPath);
235+
236+
let sep;
237+
if (Phoenix.isNativeApp && brackets.platform === "win") {
238+
sep = "\\";
239+
} else {
240+
sep = "/";
241+
}
242+
let dirSplit = Phoenix.app.getDisplayPath(virtualPath).split(sep).filter(segment => segment !== '');
243+
const root = dirSplit[0];
233244

234-
await openAndMakeDirty(externalProjectTestPath + "/test.js");
245+
await openAndMakeDirty(virtualPath);
235246

236247
// wait for the file to add to the working set
237248
await awaitsFor(function () { return workingSetListItemCount === 1; }, "Open file count to be 1");
@@ -246,9 +257,17 @@ define(function (require, exports, module) {
246257

247258
// check if the directory path has ellipsis
248259
expect(directoryText.includes("\u2026")).toBe(true);
260+
if (!Phoenix.isNativeApp) {
261+
expect(directoryText).toBe(' — /test/…/MainViewFactory-test-files/css');
262+
} else if (brackets.platform === "linux" || brackets.platform === "mac") {
263+
expect(directoryText).toBe(` — /${root}/…/MainViewFactory-test-files/css`);
264+
} else {
265+
// windows
266+
expect(directoryText).toBe(` — ${root}:\\\\…\\MainViewFactory-test-files\\css`);
267+
}
249268

250269
// the title should contain the full path
251-
expect(directorySpan.attr('title')).toBe(Phoenix.app.getDisplayPath(path.dirname(externalProjectTestPath + "/test.js")));
270+
expect(directorySpan.attr('title')).toBe(hoverFullPath);
252271

253272
// Clean up
254273
DocumentManager.getCurrentDocument()._markClean(); // so we can close without a save dialog

0 commit comments

Comments
 (0)