OSC8-URIs support in terminal (#54322)
Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes #39339 Release Notes: - Fixed hyperlinks in the terminal on UNIX
This commit is contained in:
1 parent
0a256eda7a
commit
7748c3b924
3 files changed
+22
No files matched your search
Generated
+1
@@ -17771,6 +17771,7 @@ dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"rand 0.9.3",
|
||||
"regex",
|
||||
"release_channel",
|
||||
|
||||
@@ -43,6 +43,7 @@ url.workspace = true
|
||||
util.workspace = true
|
||||
urlencoding.workspace = true
|
||||
parking_lot.workspace = true
|
||||
percent-encoding.workspace = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows.workspace = true
|
||||
|
||||
@@ -138,6 +138,10 @@ pub(super) fn find_from_grid_point<T: EventListener>(
|
||||
if let Ok(url) = Url::parse(&maybe_url_or_path) {
|
||||
if let Ok(path) = url.to_file_path_ext(path_style) {
|
||||
return (path.to_string_lossy().into_owned(), false, word_match);
|
||||
} else if let Some(path) = try_osc8_url_to_path(url)
|
||||
&& path_style.is_posix()
|
||||
{
|
||||
return (path, false, word_match);
|
||||
}
|
||||
}
|
||||
// Fallback: strip file:// prefix if URL parsing fails
|
||||
@@ -154,6 +158,22 @@ pub(super) fn find_from_grid_point<T: EventListener>(
|
||||
})
|
||||
}
|
||||
|
||||
// OSC 8 mandates that file:// URIs must be encoded as file://{host}{path}
|
||||
// We need to skip the {host} part if it's set
|
||||
fn try_osc8_url_to_path(url: url::Url) -> Option<String> {
|
||||
use percent_encoding::percent_decode;
|
||||
if url.scheme() != "file" {
|
||||
return None;
|
||||
}
|
||||
|
||||
let bytes = url
|
||||
.path_segments()?
|
||||
.skip(1)
|
||||
.flat_map(|segment| percent_decode(segment.as_bytes()))
|
||||
.collect::<Vec<u8>>();
|
||||
bytes.try_into().ok()
|
||||
}
|
||||
|
||||
fn sanitize_url_punctuation<T: EventListener>(
|
||||
url: String,
|
||||
url_match: Match,
|
||||
|
||||
Reference in new issue
Block a user