Skip to content

Commit 8194d56

Browse files
authored
Fix sorting of items in Projects Explorer (#1246)
1 parent 6e51b73 commit 8194d56

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

src/explorer/models/projectRootNode.ts

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -68,46 +68,37 @@ export class ProjectRootNode extends RootNode {
6868
return api
6969
.actionQuery(query, parameters)
7070
.then((data) => data.result.content.map((e) => e.Name))
71+
.then((entries: string[]) => {
72+
// Sort the files and folders separately an case-insensitively
73+
const folders: string[] = [];
74+
const files: string[] = [];
75+
const collator = new Intl.Collator("en");
76+
for (const entry of entries) entry.includes(".") ? files.push(entry) : folders.push(entry);
77+
return [...folders.sort(collator.compare), ...files.sort(collator.compare)];
78+
})
7179
.then((entries: string[]) =>
72-
entries
73-
.sort((a, b) => {
74-
if ((a.match(/\./g) || []).length > (b.match(/\./g) || []).length) {
75-
return 1;
76-
} else if ((a.match(/\./g) || []).length < (b.match(/\./g) || []).length) {
77-
return -1;
80+
entries.map((entry) => {
81+
const fullName = this.fullName.length
82+
? `${this.fullName}${this.category == "CSP" ? "/" : "."}${entry}`
83+
: entry;
84+
if (this.category == "CSP") {
85+
if (entry.includes(".")) {
86+
return new CSPFileNode(entry, fullName, this.options);
7887
} else {
79-
return 0;
88+
return new ProjectRootNode(entry, fullName, "dataNode:cspApplication", this.category, this.options, true);
8089
}
81-
})
82-
.map((entry) => {
83-
const fullName = this.fullName.length
84-
? `${this.fullName}${this.category == "CSP" ? "/" : "."}${entry}`
85-
: entry;
86-
if (this.category == "CSP") {
87-
if (entry.includes(".")) {
88-
return new CSPFileNode(entry, fullName, this.options);
90+
} else {
91+
if (entry.includes(".")) {
92+
if (["mac", "int", "inc"].includes(entry.split(".").pop().toLowerCase())) {
93+
return new RoutineNode(entry, fullName, this.options);
8994
} else {
90-
return new ProjectRootNode(
91-
entry,
92-
fullName,
93-
"dataNode:cspApplication",
94-
this.category,
95-
this.options,
96-
true
97-
);
95+
return new ClassNode(entry, fullName, this.options);
9896
}
9997
} else {
100-
if (entry.includes(".")) {
101-
if (["mac", "int", "inc"].includes(entry.split(".").pop().toLowerCase())) {
102-
return new RoutineNode(entry, fullName, this.options);
103-
} else {
104-
return new ClassNode(entry, fullName, this.options);
105-
}
106-
} else {
107-
return new ProjectRootNode(entry, fullName, "dataNode:packageNode", this.category, this.options);
108-
}
98+
return new ProjectRootNode(entry, fullName, "dataNode:packageNode", this.category, this.options);
10999
}
110-
})
100+
}
101+
})
111102
);
112103
}
113104
public getItems4Export(): Promise<string[]> {

0 commit comments

Comments
 (0)