Skip to content

Commit 394a281

Browse files
devvaannshabose
authored andcommitted
feat: truncate long directory names in working set
1 parent 21ecffe commit 394a281

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

src/project/WorkingSetView.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,26 +1001,60 @@ define(function (require, exports, module) {
10011001
};
10021002

10031003
/**
1004-
* Adds full directory names to elements representing passed files in working tree
1004+
* adds the directory name to external project files
1005+
* when the directory length is more than 3, we show it in this format: `<root directory>/.../<parent directory>`
1006+
* otherwise the full path
10051007
* @private
1006-
* @param {Array.<string>} filesPathList - list of fullPath strings
1008+
* @param {Array.<string>} externalProjectFiles - the list of the external project files
10071009
*/
1008-
WorkingSetView.prototype._addFullDirectoryNamesToWorkingTreeFiles = function (filesPathList) {
1009-
// filesList must have at least two files in it for this to make sense
1010-
if (!filesPathList.length) {
1010+
WorkingSetView.prototype._addDirectoryNameToExternalProjectFiles = function (externalProjectFiles) {
1011+
if(!externalProjectFiles.length) {
10111012
return;
10121013
}
10131014

1014-
// Go through open files and add directories to appropriate entries
10151015
this.$openFilesContainer.find("ul > li").each(function () {
10161016
const $li = $(this);
10171017
let filePath = $li.data(_FILE_KEY).fullPath;
1018-
const io = filesPathList.indexOf(filePath);
1018+
const io = externalProjectFiles.indexOf(filePath);
10191019
if (io !== -1) {
10201020
let dirPath = path.dirname(filePath);
1021-
dirPath = Phoenix.app.getDisplayPath(dirPath);
1022-
const $dir = $(`<span title='${Phoenix.app.getDisplayPath(filePath)}' class='directory'/>`)
1023-
.html(" &mdash; " + dirPath);
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" ? "\\" : "/";
1027+
} else {
1028+
separator = "/";
1029+
}
1030+
1031+
let dirSplit = displayPath.split(separator);
1032+
1033+
let truncatedPath = displayPath; // truncatedPath value will be shown in the UI
1034+
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];
1041+
} 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+
}
1051+
}
1052+
1053+
truncatedPath = rootDirName + separator + "\u2026" + separator + dirSplit[dirSplit.length - 1];
1054+
}
1055+
1056+
const $dir = $(`<span title='${displayPath}' class='directory'/>`)
1057+
.html(" &mdash; " + truncatedPath);
10241058
$li.children("a").append($dir);
10251059
}
10261060
});
@@ -1084,7 +1118,7 @@ define(function (require, exports, module) {
10841118
}
10851119
});
10861120

1087-
self._addFullDirectoryNamesToWorkingTreeFiles(externalProjectFiles);
1121+
self._addDirectoryNameToExternalProjectFiles(externalProjectFiles);
10881122

10891123
// Go through the map and solve the arrays with length over 1. Ignore the rest.
10901124
_.forEach(map, function (value) {

0 commit comments

Comments
 (0)