Skip to content

Commit

Permalink
picker root
Browse files Browse the repository at this point in the history
  • Loading branch information
cossonleo committed Mar 10, 2022
1 parent 8d7a25b commit 8404d88
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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`.

### `[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 @@ -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)));
}
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 @@ -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 {
Expand All @@ -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<usize>,
/// find root
pub root: FilePickerRoot,
}

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

0 comments on commit 8404d88

Please sign in to comment.