From 57f17e612ceefc3b3271bb9252b3b4f566940dd9 Mon Sep 17 00:00:00 2001 From: John Allison Date: Tue, 7 Jun 2022 23:22:16 -0400 Subject: [PATCH 1/6] Add file picker dialogue when opening a directory with :o --- helix-term/src/commands/typed.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 0b207f9478dd..4c8402fe6956 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -46,12 +46,24 @@ fn open( ensure!(!args.is_empty(), "wrong argument count"); for arg in args { let (path, pos) = args::parse_file(arg); - let _ = cx.editor.open(path, Action::Replace)?; - let (view, doc) = current!(cx.editor); - let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true)); - doc.set_selection(view.id, pos); - // does not affect opening a buffer without pos - align_view(doc, view, Align::Center); + if std::fs::canonicalize(&path)?.is_dir() { + let callback = async move { + let call: job::Callback = + Box::new(move |editor: &mut Editor, compositor: &mut Compositor| { + let picker = ui::file_picker(path.clone(), &*editor.config.load()); + compositor.push(Box::new(overlayed(picker))); + }); + Ok(call) + }; + cx.jobs.callback(callback); + } else { + let _ = cx.editor.open(path, Action::Replace)?; + let (view, doc) = current!(cx.editor); + let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true)); + doc.set_selection(view.id, pos); + // does not affect opening a buffer without pos + align_view(doc, view, Align::Center); + } } Ok(()) } From ec469a14d17c7d6d3a6bc3cfe72e0a0d4cae4e8a Mon Sep 17 00:00:00 2001 From: John Allison Date: Wed, 8 Jun 2022 02:28:01 -0400 Subject: [PATCH 2/6] remove erroneous clone --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 4c8402fe6956..2c1328e8c1be 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -50,7 +50,7 @@ fn open( let callback = async move { let call: job::Callback = Box::new(move |editor: &mut Editor, compositor: &mut Compositor| { - let picker = ui::file_picker(path.clone(), &*editor.config.load()); + let picker = ui::file_picker(path, &*editor.config.load()); compositor.push(Box::new(overlayed(picker))); }); Ok(call) From de031ac5c5148ec9d7e0c2e65310db1b868499c4 Mon Sep 17 00:00:00 2001 From: John Allison Date: Thu, 9 Jun 2022 13:36:35 -0400 Subject: [PATCH 3/6] Update helix-term/src/commands/typed.rs Co-authored-by: Michael Davis --- helix-term/src/commands/typed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index ff29d29c5de3..f27bd577850e 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -54,7 +54,7 @@ fn open( let callback = async move { let call: job::Callback = Box::new(move |editor: &mut Editor, compositor: &mut Compositor| { - let picker = ui::file_picker(path, &*editor.config.load()); + let picker = ui::file_picker(path, &editor.config()); compositor.push(Box::new(overlayed(picker))); }); Ok(call) From 87662c7f992cc5c9f71782b9e69b9beae60bdc60 Mon Sep 17 00:00:00 2001 From: John Allison Date: Mon, 1 Aug 2022 21:35:22 -0400 Subject: [PATCH 4/6] Use Mike Davis' suggestion for 'editor.set_status()' --- helix-term/src/commands/typed.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index f2b63fd579be..5c02272bd75c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -56,7 +56,10 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> ensure!(!args.is_empty(), "wrong argument count"); for arg in args { let (path, pos) = args::parse_file(arg); + // If the path is a directory, open a file picker on that directory + // Use a vector to 'reverse' the order of the opened directories if std::fs::canonicalize(&path)?.is_dir() { + cx.editor.set_status(path.to_string_lossy().to_string()); let callback = async move { let call: job::Callback = Box::new(move |editor: &mut Editor, compositor: &mut Compositor| { @@ -67,12 +70,13 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> }; cx.jobs.callback(callback); } else { - let _ = cx.editor.open(&path, Action::Replace)?; - let (view, doc) = current!(cx.editor); - let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true)); - doc.set_selection(view.id, pos); - // does not affect opening a buffer without pos - align_view(doc, view, Align::Center); + // Otherwise, just open the file + let _ = cx.editor.open(&path, Action::Replace)?; + let (view, doc) = current!(cx.editor); + let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true)); + doc.set_selection(view.id, pos); + // does not affect opening a buffer without pos + align_view(doc, view, Align::Center); } } Ok(()) From ad9b01efc5293652e3b43669b8aee0d77f8a4446 Mon Sep 17 00:00:00 2001 From: John Allison Date: Sun, 7 Aug 2022 18:07:23 -0400 Subject: [PATCH 5/6] Remove erroneous comment --- helix-term/src/commands/typed.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index ef1119d26b03..a421cab71aec 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -56,8 +56,8 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> ensure!(!args.is_empty(), "wrong argument count"); for arg in args { let (path, pos) = args::parse_file(arg); - // If the path is a directory, open a file picker on that directory - // Use a vector to 'reverse' the order of the opened directories + // If the path is a directory, open a file picker on that directory and update the status + // message if std::fs::canonicalize(&path)?.is_dir() { cx.editor.set_status(path.to_string_lossy().to_string()); let callback = async move { From 3228c4ddd5fe1bf1a811e1879d47aaeb4b7587cf Mon Sep 17 00:00:00 2001 From: John Allison Date: Thu, 22 Dec 2022 16:59:32 -0500 Subject: [PATCH 6/6] Remove editor.set_status --- helix-term/src/commands/typed.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 18d9b00d0aad..c3a7c9faabd9 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -68,13 +68,13 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> // If the path is a directory, open a file picker on that directory and update the status // message if std::fs::canonicalize(&path)?.is_dir() { - cx.editor.set_status(path.to_string_lossy().to_string()); let callback = async move { - let call: job::Callback = - Box::new(move |editor: &mut Editor, compositor: &mut Compositor| { + let call: job::Callback = job::Callback::EditorCompositor(Box::new( + move |editor: &mut Editor, compositor: &mut Compositor| { let picker = ui::file_picker(path, &editor.config()); compositor.push(Box::new(overlayed(picker))); - }); + }, + )); Ok(call) }; cx.jobs.callback(callback);