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: #1472
Superseds: #4398
  • Loading branch information
matoous committed Feb 4, 2023
1 parent 7b46a6c commit d28a23e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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
open = "3.2.0"

# config
toml = "0.7"
Expand Down
13 changes: 12 additions & 1 deletion 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 @@ -302,7 +303,7 @@ impl MappableCommand {
goto_implementation, "Goto implementation",
goto_file_start, "Goto line number <n> else file start",
goto_file_end, "Goto file end",
goto_file, "Goto files in selection",
goto_file, "Goto files/URLs in selection",
goto_file_hsplit, "Goto files in selection (hsplit)",
goto_file_vsplit, "Goto files in selection (vsplit)",
goto_reference, "Goto references",
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 d28a23e

Please sign in to comment.