Skip to content

Commit

Permalink
picker root
Browse files Browse the repository at this point in the history
  • Loading branch information
cossonleo committed Mar 15, 2022
1 parent 2b0835b commit d85a7da
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 @@ -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

0 comments on commit d85a7da

Please sign in to comment.