-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 file browser #11285
base: master
Are you sure you want to change the base?
Add file browser #11285
Changes from 10 commits
b1dcd96
bb1722a
02edda1
7902fc5
268eac8
ff833b7
006359c
1233784
0b01885
52a9cef
996ee93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,6 +393,9 @@ impl MappableCommand { | |
file_picker, "Open file picker", | ||
file_picker_in_current_buffer_directory, "Open file picker at current buffer's directory", | ||
file_picker_in_current_directory, "Open file picker at current working directory", | ||
file_browser, "Open file browser in workspace root", | ||
file_browser_in_current_buffer_directory, "Open file browser at current buffer's directory", | ||
file_browser_in_current_directory, "Open file browser at current working directory", | ||
code_action, "Perform code action", | ||
buffer_picker, "Open buffer picker", | ||
jumplist_picker, "Open jumplist picker", | ||
|
@@ -2986,6 +2989,58 @@ fn file_picker_in_current_directory(cx: &mut Context) { | |
cx.push_layer(Box::new(overlaid(picker))); | ||
} | ||
|
||
fn file_browser(cx: &mut Context) { | ||
let root = find_workspace().0; | ||
if !root.exists() { | ||
cx.editor.set_error("Workspace directory does not exist"); | ||
return; | ||
} | ||
|
||
if let Ok(picker) = ui::file_browser(root, cx.editor) { | ||
cx.push_layer(Box::new(overlaid(picker))); | ||
} | ||
} | ||
|
||
fn file_browser_in_current_buffer_directory(cx: &mut Context) { | ||
let doc_dir = doc!(cx.editor) | ||
.path() | ||
.and_then(|path| path.parent().map(|path| path.to_path_buf())); | ||
|
||
let path = match doc_dir { | ||
Some(path) => path, | ||
None => { | ||
let cwd = helix_stdx::env::current_working_dir(); | ||
if !cwd.exists() { | ||
cx.editor.set_error( | ||
"Current buffer has no parent and current working directory does not exist", | ||
); | ||
return; | ||
} | ||
cx.editor.set_error( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't call this an error, honestly. For example I'm frequently doing I think that this call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be fair, this function is called What you want to call after |
||
"Current buffer has no parent, opening file browser in current working directory", | ||
); | ||
cwd | ||
} | ||
}; | ||
|
||
if let Ok(picker) = ui::file_browser(path, cx.editor) { | ||
cx.push_layer(Box::new(overlaid(picker))); | ||
} | ||
} | ||
|
||
fn file_browser_in_current_directory(cx: &mut Context) { | ||
let cwd = helix_stdx::env::current_working_dir(); | ||
if !cwd.exists() { | ||
cx.editor | ||
.set_error("Current working directory does not exist"); | ||
return; | ||
} | ||
|
||
if let Ok(picker) = ui::file_browser(cwd, cx.editor) { | ||
cx.push_layer(Box::new(overlaid(picker))); | ||
} | ||
} | ||
|
||
fn buffer_picker(cx: &mut Context) { | ||
let current = view!(cx.editor).doc; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to set a default keybind of
<space>.
for this. Thoughts @archseer? @pascalkuthe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me but I haven't looked at this PR much yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
<space>e
could also work. Could have a<space>E
, similar in nature to the file picker.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created a PR that adds mappings and fixes the docs check drybalka#1