Sort folders first then files
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user