From 8404d88f188d78849e786c61057387ac00f3eab4 Mon Sep 17 00:00:00 2001 From: cossonleo Date: Thu, 10 Mar 2022 11:28:22 +0800 Subject: [PATCH] picker root --- book/src/configuration.md | 1 + helix-term/src/commands.rs | 13 +++++++++++-- helix-view/src/editor.rs | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/book/src/configuration.md b/book/src/configuration.md index 2e4cab8ae7a93..e99754a4e1422 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -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`. ### `[editor.auto-pairs]` Section diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 0052b43e40561..3309c20cf4605 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -2020,8 +2020,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))); } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 0eb613087d80c..479f0db6da848 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -48,6 +48,14 @@ where Ok(Duration::from_millis(millis)) } +#[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 { @@ -72,6 +80,8 @@ pub struct FilePickerConfig { /// WalkBuilder options /// Maximum Depth to recurse directories in file picker and global search. Defaults to `None`. pub max_depth: Option, + /// find root + pub root: FilePickerRoot, } impl Default for FilePickerConfig { @@ -84,6 +94,7 @@ impl Default for FilePickerConfig { git_global: true, git_exclude: true, max_depth: None, + root: FilePickerRoot::Git, } } }