mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 11:01:54 +00:00
terminal: Support clicking on "file://" URLs with line numbers (#22559)
Closes #10325 Release Notes: - Fixed an issue inside the integrated terminal where clicking on URLs that started with `file://` would sometimes not work when the path included a line number (e.g. `file:///Users/someuser/lorem.txt:221:22`)
This commit is contained in:
parent
f55a3629b0
commit
b009e72121
1 changed files with 18 additions and 16 deletions
|
@ -953,22 +953,32 @@ impl Terminal {
|
||||||
|
|
||||||
match found_word {
|
match found_word {
|
||||||
Some((maybe_url_or_path, is_url, url_match)) => {
|
Some((maybe_url_or_path, is_url, url_match)) => {
|
||||||
if *open {
|
let target = if is_url {
|
||||||
let target = if is_url {
|
// Treat "file://" URLs like file paths to ensure
|
||||||
MaybeNavigationTarget::Url(maybe_url_or_path)
|
// that line numbers at the end of the path are
|
||||||
} else {
|
// handled correctly
|
||||||
|
if let Some(path) = maybe_url_or_path.strip_prefix("file://") {
|
||||||
MaybeNavigationTarget::PathLike(PathLikeTarget {
|
MaybeNavigationTarget::PathLike(PathLikeTarget {
|
||||||
maybe_path: maybe_url_or_path,
|
maybe_path: path.to_string(),
|
||||||
terminal_dir: self.working_directory(),
|
terminal_dir: self.working_directory(),
|
||||||
})
|
})
|
||||||
};
|
} else {
|
||||||
|
MaybeNavigationTarget::Url(maybe_url_or_path.clone())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MaybeNavigationTarget::PathLike(PathLikeTarget {
|
||||||
|
maybe_path: maybe_url_or_path.clone(),
|
||||||
|
terminal_dir: self.working_directory(),
|
||||||
|
})
|
||||||
|
};
|
||||||
|
if *open {
|
||||||
cx.emit(Event::Open(target));
|
cx.emit(Event::Open(target));
|
||||||
} else {
|
} else {
|
||||||
self.update_selected_word(
|
self.update_selected_word(
|
||||||
prev_hovered_word,
|
prev_hovered_word,
|
||||||
url_match,
|
url_match,
|
||||||
maybe_url_or_path,
|
maybe_url_or_path,
|
||||||
is_url,
|
target,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -990,7 +1000,7 @@ impl Terminal {
|
||||||
prev_word: Option<HoveredWord>,
|
prev_word: Option<HoveredWord>,
|
||||||
word_match: RangeInclusive<AlacPoint>,
|
word_match: RangeInclusive<AlacPoint>,
|
||||||
word: String,
|
word: String,
|
||||||
is_url: bool,
|
navigation_target: MaybeNavigationTarget,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) {
|
) {
|
||||||
if let Some(prev_word) = prev_word {
|
if let Some(prev_word) = prev_word {
|
||||||
|
@ -1009,14 +1019,6 @@ impl Terminal {
|
||||||
word_match,
|
word_match,
|
||||||
id: self.next_link_id(),
|
id: self.next_link_id(),
|
||||||
});
|
});
|
||||||
let navigation_target = if is_url {
|
|
||||||
MaybeNavigationTarget::Url(word)
|
|
||||||
} else {
|
|
||||||
MaybeNavigationTarget::PathLike(PathLikeTarget {
|
|
||||||
maybe_path: word,
|
|
||||||
terminal_dir: self.working_directory(),
|
|
||||||
})
|
|
||||||
};
|
|
||||||
cx.emit(Event::NewNavigationTarget(Some(navigation_target)));
|
cx.emit(Event::NewNavigationTarget(Some(navigation_target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue