aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index d545480b..5c59962d 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -507,6 +507,8 @@ impl MappableCommand {
command_palette, "Open command palette",
goto_word, "Jump to a two-character label",
extend_to_word, "Extend to a two-character label",
+ open_or_focus_explorer, "Open or focus explorer",
+ reveal_current_file, "Reveal current file in explorer",
);
}
@@ -2834,6 +2836,49 @@ fn file_picker_in_current_directory(cx: &mut Context) {
cx.push_layer(Box::new(overlaid(picker)));
}
+fn open_or_focus_explorer(cx: &mut Context) {
+ cx.callback.push(Box::new(
+ |compositor: &mut Compositor, cx: &mut compositor::Context| {
+ if let Some(editor) = compositor.find::<ui::EditorView>() {
+ match editor.explorer.as_mut() {
+ Some(explore) => explore.focus(),
+ None => match ui::Explorer::new(cx) {
+ Ok(explore) => editor.explorer = Some(explore),
+ Err(err) => cx.editor.set_error(format!("{}", err)),
+ },
+ }
+ }
+ },
+ ));
+}
+
+fn reveal_file_in_explorer(cx: &mut Context, path: Option<PathBuf>) {
+ cx.callback.push(Box::new(
+ |compositor: &mut Compositor, cx: &mut compositor::Context| {
+ if let Some(editor) = compositor.find::<ui::EditorView>() {
+ (|| match editor.explorer.as_mut() {
+ Some(explorer) => match path {
+ Some(path) => explorer.reveal_file(path),
+ None => explorer.reveal_current_file(cx),
+ },
+ None => {
+ editor.explorer = Some(ui::Explorer::new(cx)?);
+ if let Some(explorer) = editor.explorer.as_mut() {
+ explorer.reveal_current_file(cx)?;
+ }
+ Ok(())
+ }
+ })()
+ .unwrap_or_else(|err| cx.editor.set_error(err.to_string()))
+ }
+ },
+ ));
+}
+
+fn reveal_current_file(cx: &mut Context) {
+ reveal_file_in_explorer(cx, None)
+}
+
fn buffer_picker(cx: &mut Context) {
let current = view!(cx.editor).doc;