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 a config to decide how to find root of file pciker #1781

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ available, which is not defined by default.
|`git-global` | Enables reading global .gitignore, whose path is specified in git's config: `core.excludefile` option. | true
|`git-exclude` | Enables reading `.git/info/exclude` files. | true
|`max-depth` | Set with an integer value for maximum depth to recurse. | Defaults to `None`.
|`root` | Set the option decide how to find root dir, values: "pwd", "git", "file". | Defaults to `git`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than config, why not two methods, #1600 and #1352 ? Then the user can remap the default shortcut if they want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's better.


### `[editor.auto-pairs]` Section

Expand Down
13 changes: 11 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,8 +2026,17 @@ fn append_mode(cx: &mut Context) {
}

fn file_picker(cx: &mut Context) {
// We don't specify language markers, root will be the root of the current git repo
let root = find_root(None, &[]).unwrap_or_else(|| PathBuf::from("./"));
use helix_view::editor::FilePickerRoot;
let root = match cx.editor.config.file_picker.root {
FilePickerRoot::Git => find_root(None, &[]).unwrap_or_else(|| PathBuf::from("./")),
FilePickerRoot::Pwd => PathBuf::from("./"),
FilePickerRoot::File => doc!(cx.editor)
.path()
.and_then(|p| p.parent())
.map(|p| p.to_path_buf())
.unwrap_or_else(|| PathBuf::from("./")),
};

let picker = ui::file_picker(root, &cx.editor.config);
cx.push_layer(Box::new(overlayed(picker)));
}
Expand Down
11 changes: 11 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ where
)
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub enum FilePickerRoot {
Git,
Pwd,
File,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct FilePickerConfig {
Expand All @@ -84,6 +92,8 @@ pub struct FilePickerConfig {
/// WalkBuilder options
/// Maximum Depth to recurse directories in file picker and global search. Defaults to `None`.
pub max_depth: Option<usize>,
/// find root
pub root: FilePickerRoot,
}

impl Default for FilePickerConfig {
Expand All @@ -96,6 +106,7 @@ impl Default for FilePickerConfig {
git_global: true,
git_exclude: true,
max_depth: None,
root: FilePickerRoot::Git,
}
}
}
Expand Down