Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to group directories above files. #21

Merged
merged 1 commit into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ This extension is based on [advanced-open-file](https://github.com/Osmose/advanc
## Settings
### `vscode-advanced-open-file.selectPath`

If you set `true`, it is enabled path selection on opening filter box. (Default: `false`)
If set to `true`, when the picker is opened, the entire path will be selected (i.e. typing immediately will replace the path instead of adding to it). (Default: `false`)

### `vscode-advanced-open-file.groupDirectoriesFirst`

If set to `true`, directories will be grouped before files. (Default: `false`)

## LICENSE

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
"type": "boolean",
"default": false,
"description": "Select the path when QuickPick opens"
},
"vscode-advanced-open-file.groupDirectoriesFirst": {
"type": "boolean",
"default": false,
"description": "Group directories before files"
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/advancedOpenFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ async function createFilePickItems(value: string): Promise<ReadonlyArray<QuickPi
})
);

// Group directories first if desired
if (workspace.getConfiguration().get("vscode-advanced-open-file.groupDirectoriesFirst")) {
filePickItems.sort((fileA, fileB) => {
if (fileA.filetype === FileType.Directory && fileB.filetype !== FileType.Directory) {
return -1;
} else if (fileA.filetype !== FileType.Directory && fileB.filetype === FileType.Directory) {
return 1;
}

return 0;
});
}

if (!fragment && directory !== fsRoot) {
const parent = path.dirname(directory);
filePickItems.unshift(new FilePickItem(parent, FileType.Directory, ".."));
Expand Down