picker: add sort option (#11021)

This commit is contained in:
Anshul Dalal 2024-06-25 15:08:18 +05:30
parent a982e5ce26
commit 8ea0394c60
3 changed files with 8 additions and 1 deletions

View File

@ -160,6 +160,7 @@ ### `[editor.file-picker]` Section
|`git-ignore` | Enables reading `.gitignore` files | `true`
|`git-global` | Enables reading global `.gitignore`, whose path is specified in git's config: `core.excludesfile` option | `true`
|`git-exclude` | Enables reading `.git/info/exclude` files | `true`
|`sort` | Enables sorting entries by file name | `true`
|`max-depth` | Set with an integer value for maximum depth to recurse | Unset by default
Ignore files can be placed locally as `.ignore` or put in your home directory as `~/.ignore`. They support the usual ignore and negative ignore (unignore) rules used in `.gitignore` files.

View File

@ -188,10 +188,13 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker
.git_ignore(config.file_picker.git_ignore)
.git_global(config.file_picker.git_global)
.git_exclude(config.file_picker.git_exclude)
.sort_by_file_name(|name1, name2| name1.cmp(name2))
.max_depth(config.file_picker.max_depth)
.filter_entry(move |entry| filter_picker_entry(entry, &absolute_root, dedup_symlinks));
if config.file_picker.sort {
walk_builder.sort_by_file_name(|name1, name2| name1.cmp(name2));
}
walk_builder.add_custom_ignore_filename(helix_loader::config_dir().join("ignore"));
walk_builder.add_custom_ignore_filename(".helix/ignore");

View File

@ -195,6 +195,8 @@ pub struct FilePickerConfig {
/// Enables reading `.git/info/exclude` files.
/// Whether to hide files listed in .git/info/exclude in file picker and global search results. Defaults to true.
pub git_exclude: bool,
/// Weather to sort picker entries by file name. Defaults to true.
pub sort: bool,
/// WalkBuilder options
/// Maximum Depth to recurse directories in file picker and global search. Defaults to `None`.
pub max_depth: Option<usize>,
@ -211,6 +213,7 @@ fn default() -> Self {
git_ignore: true,
git_global: true,
git_exclude: true,
sort: true,
max_depth: None,
}
}