Skip to content

Commit

Permalink
feat(commands): open urls with goto_file command
Browse files Browse the repository at this point in the history
Add capability for `goto_file` command to open an URL under cursor.

Fixes: helix-editor#1472
Superseds: helix-editor#4398
  • Loading branch information
matoous committed Feb 4, 2023
1 parent 7b46a6c commit 2a93372
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ ignore = "0.4"
pulldown-cmark = { version = "0.9", default-features = false }
# file type detection
content_inspector = "0.2.4"
# openning URLs/files
open = "3"

# config
toml = "0.7"
Expand Down
11 changes: 11 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod lsp;
pub(crate) mod typed;

pub use dap::*;
use helix_lsp::Url;
use helix_vcs::Hunk;
pub use lsp::*;
use tui::widgets::Row;
Expand Down Expand Up @@ -1134,6 +1135,16 @@ fn goto_file_impl(cx: &mut Context, action: Action) {
for sel in paths {
let p = sel.trim();
if !p.is_empty() {
if let Ok(url) = Url::parse(p) {
if let Err(e) = open::that(url.as_str()) {
cx.editor.set_error(format!(
"Open file failed for url '{}': {:?}",
url.as_str(),
e
));
}
return;
}
if let Err(e) = cx.editor.open(&PathBuf::from(p), action) {
cx.editor.set_error(format!("Open file failed: {:?}", e));
}
Expand Down

0 comments on commit 2a93372

Please sign in to comment.