Sort folders first then files
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
"name": "prompter",
|
"name": "prompter",
|
||||||
"displayName": "Prompter",
|
"displayName": "Prompter",
|
||||||
"description": "Easy prompt generation and apply edits using prompter.",
|
"description": "Easy prompt generation and apply edits using prompter.",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"publisher": "abhishekbhakat",
|
"publisher": "abhishekbhakat",
|
||||||
"repository": "https://github.com/abhishekbhakat/prompter",
|
"repository": "https://git.bhakat.dev/abhishekbhakat/Prompter",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.98.0"
|
"vscode": "^1.98.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -85,7 +85,21 @@ export class PrompterTreeProvider implements vscode.TreeDataProvider<FileTreeIte
|
|||||||
try {
|
try {
|
||||||
const files = await vscode.workspace.fs.readDirectory(vscode.Uri.file(dirPath));
|
const files = await vscode.workspace.fs.readDirectory(vscode.Uri.file(dirPath));
|
||||||
|
|
||||||
return files.map(([name, type]) => {
|
// Sort by type first (directories first), then alphabetically by name
|
||||||
|
const sortedFiles = [...files].sort((a, b) => {
|
||||||
|
const [nameA, typeA] = a;
|
||||||
|
const [nameB, typeB] = b;
|
||||||
|
|
||||||
|
// If types are different, directories (type 2) come before files (type 1)
|
||||||
|
if (typeA !== typeB) {
|
||||||
|
return typeB - typeA; // Descending order by type puts directories first
|
||||||
|
}
|
||||||
|
|
||||||
|
// If types are the same, sort alphabetically by name
|
||||||
|
return nameA.localeCompare(nameB, undefined, { sensitivity: 'base' });
|
||||||
|
});
|
||||||
|
|
||||||
|
return sortedFiles.map(([name, type]) => {
|
||||||
const filePath = path.join(dirPath, name);
|
const filePath = path.join(dirPath, name);
|
||||||
const uri = vscode.Uri.file(filePath);
|
const uri = vscode.Uri.file(filePath);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user