From a07f7f093744cd01602d0ed513221ebf5f551f8b Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 3 Feb 2024 20:32:34 -0500 Subject: [PATCH] Updated goto_file_impl to handle gf line pos like :open --- helix-term/src/commands.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4df3278b8..4eb776163 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1162,10 +1162,6 @@ fn goto_file_impl(cx: &mut Context, action: Action) { let (view, doc) = current_ref!(cx.editor); let text = doc.text(); let selections = doc.selection(view.id); - let rel_path = doc - .relative_path() - .map(|path| path.parent().unwrap().to_path_buf()) - .unwrap_or_default(); let mut paths: Vec<_> = selections .iter() .map(|r| text.slice(r.from()..r.to()).to_string()) @@ -1204,14 +1200,24 @@ fn goto_file_impl(cx: &mut Context, action: Action) { return open_url(cx, url, action); } - let path = &rel_path.join(p); + let (path, pos) = args::parse_file(p); if path.is_dir() { - let picker = ui::file_picker(path.into(), &cx.editor.config()); + let picker = ui::file_picker(path, &cx.editor.config()); cx.push_layer(Box::new(overlaid(picker))); - } else if let Err(e) = cx.editor.open(path, action) { - cx.editor.set_error(format!("Open file failed: {:?}", e)); + } else { + match cx.editor.open(path.as_path(), action) { + Ok(_) => { + let (view, doc) = current!(cx.editor); + let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true)); + doc.set_selection(view.id, pos); + align_view(doc, view, Align::Center); + } + Err(e) => { + cx.editor.set_error(format!("Open file failed: {:?}", e)); + } } } + } } /// Opens the given url. If the URL points to a valid textual file it is open in helix.