Sort folders first then files

This commit is contained in:
2025-03-27 06:28:16 +00:00
parent 8246879bea
commit bea2ea2a0f
2 changed files with 17 additions and 3 deletions

View File

@@ -85,7 +85,21 @@ export class PrompterTreeProvider implements vscode.TreeDataProvider<FileTreeIte
try {
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 uri = vscode.Uri.file(filePath);