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 Nov 19, 2023
1 parent b306b25 commit 1059a02
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
33 changes: 33 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions helix-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.7"
url = "2.3.1"

imara-diff = "0.1.0"

Expand Down
1 change: 1 addition & 0 deletions helix-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use encoding_rs as encoding;
pub use url;

pub mod auto_pairs;
pub mod chars;
Expand Down
2 changes: 2 additions & 0 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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
14 changes: 13 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use helix_core::{
textobject,
tree_sitter::Node,
unicode::width::UnicodeWidthChar,
url::Url,
visual_offset_from_block, Deletion, LineEnding, Position, Range, Rope, RopeGraphemes,
RopeReader, RopeSlice, Selection, SmallVec, Tendril, Transaction,
};
Expand Down Expand Up @@ -331,7 +332,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 @@ -1193,6 +1194,17 @@ 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;
}

let path = &rel_path.join(p);
if path.is_dir() {
let picker = ui::file_picker(path.into(), &cx.editor.config());
Expand Down
2 changes: 1 addition & 1 deletion helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ where
}

use helix_lsp::{lsp, Client, LanguageServerName};
use url::Url;
use helix_core::url::Url;

impl Document {
pub fn from(
Expand Down

0 comments on commit 1059a02

Please sign in to comment.